This is a migrated thread and some comments may be shown as answers.

[Solved] DropDownList in RadGrid

4 Answers 348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GarryP
Top achievements
Rank 1
GarryP asked on 24 Apr 2009, 01:54 PM
Hi, I have added dropdownlist for the each raws in a radgrid. I have managed to add "low,normal and high options  inside the dropdownlist but". I can not get the selected value. in the dropdownlist. I used the code below;

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound


        If TypeOf e.Item Is Telerik.WebControls.GridDataItem Then
            Dim item As Telerik.WebControls.GridDataItem = DirectCast(e.Item, Telerik.WebControls.GridDataItem)
            Dim ddl As DropDownList = DirectCast(item("Temp").FindControl("DropDownList1"), DropDownList)
            
            ddl.Items.Add("Low")
            ddl.Items.Add("Normal")
            ddl.Items.Add("High")
           

            MsgBox(ddl.SelectedValue)
          
           End If


    End Sub

ddl.SelectedValue only gives me the Low option, when i run the page but when i select normal or high or low again. It doesnt seem to be doing anything so i also added the code below.

Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged
        MsgBox(ddl.SelectedValue)
    End Sub

But still no use. So is there a way of getting the selected item of the dropdownlist in radgrid?




4 Answers, 1 is accepted

Sort by
0
Diego
Top achievements
Rank 1
answered on 24 Apr 2009, 04:15 PM
I have the same problem, but i  use a ObjectDataSource to retrieve data and populate the DDL.
Thanks.
0
Tsvetoslav
Telerik team
answered on 27 Apr 2009, 10:02 AM
Hi Garry,

The dropdownlist should behave as expected and its selected value be accessible through its SelectedValue property. Could you post your aspx and code behind for the relevant page (please, use the Code Formatter tool of the html editor).

Thank you.

Sincerely yours,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
GarryP
Top achievements
Rank 1
answered on 27 Apr 2009, 03:02 PM
Hi,

I used the code below only to add dropdownlist for each coloumn.


<radg:GridTemplateColumn UniqueName="TemplateColumn">
        <ItemTemplate>
            <asp:DropDownList ID="DropDownList1" AutoPostBack="true" DataTextField="Priority" DataSourceID="SqlDataSource1" DataValueField="Priority" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>
        </ItemTemplate>
        </radg:GridTemplateColumn>

and I used, the vb.net code below to populate the lists but it only gets the first one, when aspx form loads then when i select other items it doesnt do anything.

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound


        If TypeOf e.Item Is Telerik.WebControls.GridDataItem Then
            Dim item As Telerik.WebControls.GridDataItem = DirectCast(e.Item, Telerik.WebControls.GridDataItem)
            Dim ddl As DropDownList = DirectCast(item("Temp").FindControl("DropDownList1"), DropDownList)
            
            ddl.Items.Add("Low")
            ddl.Items.Add("Normal")
            ddl.Items.Add("High")
           

            MsgBox(ddl.SelectedValue)
          
           End If


    End Sub

Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged
        MsgBox(ddl.SelectedValue)
    End Sub

Is there an easier way in vb.net?

Thanks


0
Tsvetoslav
Telerik team
answered on 29 Apr 2009, 12:17 PM
Hello GarryP,

I could not reproduce the described prolem.

Please, review the attached sample for comparison.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
GarryP
Top achievements
Rank 1
Answers by
Diego
Top achievements
Rank 1
Tsvetoslav
Telerik team
GarryP
Top achievements
Rank 1
Share this question
or