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

DropDown list inside a Radgrid Help

3 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sima
Top achievements
Rank 1
Sima asked on 27 Sep 2012, 08:15 PM
Hi,

I have a dropdown list inside the radgrid 

<telerik:GridTemplateColumn  HeaderText="" UniqueName="Answer" DataField="Answer"  >
                    <ItemTemplate>
                    <asp:DropDownList ID="ddlAnswer" runat="server"   DataTextField="Answer"
DataValueField="Answer" >
                    <asp:ListItem  Value="Yes" >Yes</asp:ListItem>
                    <asp:ListItem  Value="No" >No</asp:ListItem>
                    </asp:DropDownList>
                    </ItemTemplate>
                     </telerik:GridTemplateColumn>

If the user selects No and hits submit button the record will be updated in the database and below the answer No will be saved.(Database is updating properly)

When I click on this page again or refresh the page the page should be loaded with all the correct data from the database.

 every time the page loads all data except this drop down is getting binded properly. There are few records where the user selected No but still the drop down is showing Yes. How can I make No as the selected item?

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Sep 2012, 05:19 AM
Hi Sima,

Please try the following code snippet to show the value in the Database.

If you are binding the RadGrid Declaratively, please provide the DataSourceID and SelectedValue to show the Updated value:
ASPX:
<asp:DropDownList ID="ddlAnswer" runat="server" DataSourceID="SqlDataSource1"  DataTextField="Answer" SelectedValue='<%# Bind("Answer") %>' DataValueField="Answer" ></asp:DropDownList>

 

If you are binding the RadGrid Code behind:
ASPX:

<asp:DropDownList ID="ddlAnswer" runat="server" >/asp:DropDownList>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            DropDownList ddl = (DropDownList)item.FindControl("ddlAnswer");
            ddl.DataSource = yourdatasource;
            ddl.DataTextField = "Answer";
            ddl.DataValueField = "Answer";
            ddl.SelectedValue = (string)DataBinder.Eval(e.Item.DataItem, "Answer").ToString();
            ddl.DataBind();
        }
}

Thanks,
Shinu.


0
Sima
Top achievements
Rank 1
answered on 28 Sep 2012, 02:41 PM
Hi Shinu,

I am using vb.net. I will try to do the same in vb.net, But if you can can you please post this answer in vb.net
0
Accepted
Pavlina
Telerik team
answered on 29 Sep 2012, 09:17 AM
Hi,

You can use the Telerik Code Converter tool:
http://converter.telerik.com/

Kind regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Sima
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sima
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or