在RadGrid FormTemplate中查找控件

时间:2013-04-18 10:32:34

标签: asp.net telerik radgrid

让我说我有这个网格,

<telerik:RadGrid
    ...........................
    ...........................
    <FormTemplate>
            <asp:TextBox ID="txtDescription" runat="server" />
    </FormTemplate>
    ...........................
    ...........................
    ...........................

现在在代码背后我需要在DataSource1_Updating事件中使用txtDescription,

    protected void DataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e){

这可能吗?

1 个答案:

答案 0 :(得分:1)

以下是我修复此问题的方法。定义了一个EditCommand,

    protected void RadGrid1_EditCommand(object sender, GridCommandEventArgs e)
    {
        ViewState["CurrentIndex"] = e.Item.ItemIndex;
    }

在我的活动中,

protected void DataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e){

        var currentIndex = (int)ViewState["CurrentIndex"];
        var form = RadGrid1.Items[currentIndex].EditFormItem;
        var txtDescription= form.FindControl("txtDescription") as RadComboBox;