DataGrid with DropDownList blues

Discussion in 'ASP .Net Datagrid Control' started by Igor Stavnitser, Dec 31, 2004.

  1. PLEASE HELP!This is driving me insane.

    I have a datagrid with a templatecolumn.
    The template column contains drop-down list. I populate the list with
    values using OnDataBinding event of the DropDownList control. In that
    same event handler I also set the selected item. I stepped through the
    code and ensured that 'ddl.SelectedValue =
    dti.DataItem("FieldGroupID")' is correct, meaning that ddl.Items
    contains an item that I am setting, and dti.DataItem("FieldGroupID")
    returns correct available value!

    ASPX code:
    <asp:DataGrid id="dtgFieldOrder" runat="server"
    AutoGenerateColumns="False">
    <Columns>
    <asp:BoundColumn DataField=FieldName
    HeaderText="Field Name"></asp:BoundColumn>

    <asp:TemplateColumn><ItemTemplate>
    <input type=hidden runat=server

    value='<%#DataBinder.Eval(Container.DataItem,"FieldPositionID")%>'>
    <asp:DropDownList runat=server
    OnDataBinding="PopulateList"
    OnSelectedIndexChanged="GroupSelectionChanged"
    AutoPostBack=True
    ID=GroupSelector>
    </asp:DropDownList>
    </ItemTemplate></asp:TemplateColumn>
    .....

    Corresponding Codebehind:
    Protected Sub PopulateList(ByVal sender As Object, ByVal e As
    EventArgs)
    Dim ddl As DropDownList = CType(sender, DropDownList)
    ddl.DataSource = dtGroups
    ddl.DataTextField = "FieldGroupName"
    ddl.DataValueField = "ID"
    RemoveHandler ddl.DataBinding, AddressOf PopulateList
    ddl.DataBind()
    Dim dti As DataGridItem = ddl.NamingContainer

    'The following statement executes fine, but does not set selected
    value!!!
    'I have also tried another way of doing it below no luck with either
    ddl.SelectedValue = dti.DataItem("FieldGroupID")

    'Another way in which it does not work
    'Dim lb As ListItem =
    ddl.Items.FindByValue(dti.DataItem("FieldGroupID"))
    'lb.Selected = True
    End Sub
     
    Igor Stavnitser, Dec 31, 2004
    #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. Dietrich
    Replies:
    1
    Views:
    649
    Joe Smith
    Jul 22, 2004
  2. Max
    Replies:
    0
    Views:
    460
  3. Akshay Kumar

    session state blues

    Akshay Kumar, Apr 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    314
    Akshay Kumar
    Apr 1, 2004
  4. Alap Ghosh

    Redirect Blues - Urgent Help needed

    Alap Ghosh, Jun 10, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    318
    Alap Ghosh
    Jun 10, 2004
  5. Phil Streiff
    Replies:
    3
    Views:
    904
    Teemu Keiski
    Apr 25, 2004
Loading...

Share This Page