Telerik Radgrid访问值

时间:2013-12-31 02:29:35

标签: telerik telerik-grid

我想访问Telerik radgrid中的插入表单的值。我怎么能这样做这就是我想要的

 protected void RadGrid3_InsertCommand(object sender, GridCommandEventArgs e)
    {


        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {

            GridEditableItem editedItem = e.Item as GridEditableItem;

            string a = (editedItem.FindControl("ID") as TextBox).Text;
            string b = (editedItem.FindControl("Quantity") as TextBox).Text;


        }
 }

它引发了以下错误

Object reference not set to an instance of an object.

1 个答案:

答案 0 :(得分:0)

编辑或插入网格项时,您可以访问和修改可编辑项目中生成的控件(参考Telerik文档)。 尝试这样的事情:

protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
   GridEditableItem editableItem = e.Item as GridEditableItem;
   string a= editableItem["Id"].Controls[0] as TextBox;
   string b= editableItem["Quantity"].Controls[0] as TextBox;

 }
}

请注意,我尚未测试上述代码段。有关更多参考资料,您可以查看here