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

[Solved] Problem editing dropdownlist item in the User Control

1 Answer 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rks
Top achievements
Rank 1
rks asked on 08 Oct 2009, 02:11 PM

Hi,
I am using Visual Studio 2005, Rad Conrtols for ASP.NET Q1 2008 and .net Framework 2.0 and C# Programming.
I am editing Rad Grid using User Control Form. I have a problem when editing dropdown list item.
When I click the edit command button on the grid, the User Control form shows up. All the Text boxes are filled with the correct values. But, the dropdown List which is databound in Code behind always shows the first value in the dropdownlist.
Is there a way to set the selected Value of the Dropdown list to show the current value of the cell in Grid.
Also can you please let me know what event is fired when the edit command button is clicked?


Thanks,
RKS

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Oct 2009, 08:21 AM
Hello RKS,

You can try out the following code to set the edit form dropdownlist's text depending on the row to which the control belongs:
c#(aspx):
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem item = (GridEditFormItem)e.Item; 
            UserControl cntrl = (UserControl)item.FindControl(GridEditFormItem.EditFormUserControlID); 
            DropDownList ddl = (DropDownList)cntrl.FindControl("DropDownList1"); 
            ddl.DataSourceID = "SqlDataSource1"
            ddl.DataTextField = "CompanyName"
            ddl.Text = DataBinder.Eval(item.DataItem, "CompanyName").ToString(); 
        }        
    } 

On clicking the Edit button the EditCommand is triggered, but if you want to access controls in the EditForm, then you can use the ItemDataBound event as shown in the above example.

Thanks
Princy.
Tags
Grid
Asked by
rks
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or