0

我的 Telerik:RadGrid 标签:

<telerik:RadGrid ID="grdSettlement" runat="server" AllowFilteringByColumn="True"
    DataSourceID="SqlDataSource1" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True"
    AllowAutomaticInserts="true" OnInsertCommand="grdSettlement_InsertCommand">

我的专栏:

<telerik:GridTemplateColumn DataField="NO" FilterControlAltText="Filter NO column"
                HeaderText="NO" SortExpression="NO" UniqueName="NO" DataType="System.Int64">
                <InsertItemTemplate>
                    <telerik:RadNumericTextBox runat="server" ID="No">
                    </telerik:RadNumericTextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <%# Eval("NO") %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>

C# 代码来访问它:

protected void grdSettlement_InsertCommand(object source, GridItemEventArgs e)
{
    ((e.Item as GridEditableItem)["NO"].Controls[0] as TextBox).Text = "007";
}

我可以写一些代码,但是给我一个编译错误...帮我解决这个问题...

4

3 回答 3

2

它正在使用这个:

.aspx

<telerik:RadGrid ID="grdSettlement" runat="server" AllowFilteringByColumn="True"
    CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" AllowAutomaticDeletes="True"
    AllowAutomaticUpdates="True" AutoGenerateColumns="False" AllowAutomaticInserts="true"
    OnItemDataBound="grdSettlement_ItemDataBound">

.aspx.cs

protected void grdSettlement_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        RadNumericTextBox txtNo = item.FindControl("txtNo") as RadNumericTextBox;
        txtNo.Value = 7;
    }
}
于 2012-04-02T13:08:49.027 回答
0
//protected void grdSettlement_InsertCommand(object source, GridItemEventArgs e)
protected void grdSettlement_InsertCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem ge = e.Item as GridEditableItem;
    if (ge != null)
    {
        //Good way is change TextBox ID 
        TextBox tb = ge["No"].FindControl("No") as TextBox;
        if (tb != null)
        {
            tb.Text = "007";
        }
    }
}

控制不一定是第一位的。
尝试一下。

于 2012-03-29T11:16:18.760 回答
0

请检查下面的代码片段。

.aspx

<telerik:GridTemplateColumn DataField="NO" FilterControlAltText="Filter NO column"
                    HeaderText="NO" SortExpression="NO" UniqueName="NO" DataType="System.Int64">
                    <InsertItemTemplate>
                        <telerik:RadNumericTextBox runat="server" ID="txtNo">
                        </telerik:RadNumericTextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <%# Eval("NO") %>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

.aspx.cs

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {

if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item is GridDataInsertItem)
        {
              GridEditableItem item = (GridEditableItem)e.Item;
              RadNumericTextBox txtNo = item.FindControl("txtNo") as RadNumericTextBox;
              txtNo.Value = 7;
        }

}
于 2012-03-31T05:19:27.873 回答