Unable to get selected values from dropdownlist, present in DataGrid.

Discussion in 'ASP .Net Datagrid Control' started by gopal.panda@gmail.com, Oct 9, 2005.

  1. Guest

    Hi,
    I am unable to get the values from a dropdownlist which is present
    in Editable Template Column of the datagrid. I am using C# as backend
    code. For refrence i am pasting the code snippets.

    public void dgBanner_Update(object sender,DataGridCommandEventArgs e)
    {
    DropDownList tempDDL =
    (DropDownList)(e.Item.FindControl("ddLocation"));
    string txtTemp = ((TextBox)(e.Item.FindControl("txtImageId"))).Text;
    string tempSelected = tempDDL.SelectedItem.Value;
    }
    public void dgBanner_Edit(object sender, DataGridCommandEventArgs E)
    {
    dgBanner.EditItemIndex = System.Convert.ToInt32(E.Item.ItemIndex);
    strCurrentLocation =
    ((Label)(E.Item.FindControl("lblImageLocation"))).Text.ToUpper();
    FillGrid();
    }

    public void dgBanner_ItemDataBound(object sender, DataGridItemEventArgs
    e)
    {
    if (e.Item.ItemType == ListItemType.EditItem)
    {
    DropDownList myDropDown = null;
    myDropDown = (DropDownList)(e.Item.FindControl("ddLocation"));
    myDropDown.SelectedIndex =
    myDropDown.Items.IndexOf(myDropDown.Items.FindByText(strCurrentLocation));
    }
    }

    HERE GOES THE ASP.NET CODE SNIPPETS.

    <asp:datagrid id="dgBanner" runat="server" Width="70%"
    AllowPaging="True" CssClass="alt1Active"autogeneratecolumns="False"
    OnEditCommand="dgBanner_Edit" OnItemDataBound="dgBanner_ItemDataBound"
    OnCancelCommand="dgBanner_Cancel" OnUpdateCommand="dgBanner_Update">
    <Columns>
    <asp:TemplateColumn HeaderText="Image Location">
    <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:Label ID="lblImageLocation" Text='<%#
    DataBinder.Eval(Container.DataItem, "ImageLocation")%>' Runat="server"
    />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox id="txtImageId" Visible="False"
    Text='<%#DataBinder.Eval(Container.DataItem, "ImageId")
    %>'runat="server"/>
    <asp:Label ID="lblEditImageLocation" Text='<%#
    DataBinder.Eval(Container.DataItem, "ImageLocation")%>' Runat="server"
    />
    <asp:DropDownList ID="ddLocation"
    OnSelectedIndexChanged="ddLocation_SelectedIndexChanged" DataSource=
    "<%# FillDropDown() %>" DataTextField="ImageLocation"
    DataValueField="ImageLocation" Runat="server">
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    , Oct 9, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf Wahner
    Replies:
    5
    Views:
    620
    Bob Foster
    Dec 24, 2003
  2. Wayne Erfling
    Replies:
    0
    Views:
    453
    Wayne Erfling
    Oct 13, 2006
  3. Iain
    Replies:
    3
    Views:
    919
  4. Nathan Sokalski
    Replies:
    0
    Views:
    595
    Nathan Sokalski
    Oct 5, 2008
  5. Nathan Sokalski

    Selected ListItem in DropDownList does not appear selected

    Nathan Sokalski, Oct 5, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    284
    Nathan Sokalski
    Oct 5, 2008
Loading...

Share This Page