1

以下のように RadGrid フォーム テンプレートを使用しています。

<EditFormSettings EditFormType="Template">
    <FormTemplate>
        <table id="tblEditForm" cellpadding="2" cellspacing="2" width="100%" border="2px"
            class="tblEditForm">                           
            <tr>
                <th>
                    Server Name:
                </th>
                <td>
                    <asp:TextBox ID="tbServerName" runat="server" Text='<%# Bind("ServerName") %>' CssClass="tbServerName">
                    </asp:TextBox>
                </td>
            </tr>                                        
            <tr>
                <td colspan="2">
                    <div style="text-align: left; padding-left: 10px;display: inline; width: 50%">

                        <asp:LinkButton ID="lbTestConnection" runat="server" Text="Test Connection" CommandName="TestConnection" />
                        (It may take up to 15 seconds.)
                        <br />                                                                         
                    </div>
                    <asp:Label ID="lblTestConnectionResult" runat="server" CssClass="testConnectionResult"></asp:Label>      
                    <div style="text-align: right; padding-right: 10px;display: inline; float: right;">
                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                        </asp:Button>&nbsp;
                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                            CommandName="Cancel"></asp:Button>
                    </div>
                </td>
            </tr>
        </table>
    </FormTemplate>
</EditFormSettings>

私の RadGrid でリンクの更新ボタンをクリックすると、編集フォームが表示されます。次に、Test Connection リンク ボタンをクリックすると、ItemCommand イベントが発生します。

public void OnRadGridItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "TestConnection")
    {               
        var gridEditFormItem = e.Item as GridEditFormItem;
        if (gridEditFormItem == null)
            throw new ApplicationException("gridEditFormItem is null");
        var serverNameTextBox = gridEditFormItem.FindControl("tbServerName") as TextBox;
    }
}

問題は、この段階で gridEditFormItem 変数が null であるため、たとえばサーバー名テキスト ボックスの値を把握できないことです。

RadGrid ItemCommand イベント ハンドラーでテキスト ボックスの値を取得する方法は?

代わりに、RadGrid のデフォルトのリンク挿入ボタンをクリックすると、gridEditFormItem に値があるので、そこにあるテキスト ボックスの値を簡単に見つけることができます。

助けてください。

ありがとう、

4

3 に答える 3

2

それを私が直した :)

 var gridEditFormItem = e.Item as GridEditFormItem ?? ((GridDataItem)(e.Item)).EditFormItem;

                if (gridEditFormItem == null)
                    throw new ApplicationException("gridEditFormItem is null");

挿入時、e.Item は GridEditFormItem です。更新時、e.Item は GridDataItem です!

于 2011-10-26T14:10:18.787 に答える
0

itemcommandでasp.netのブローコードをテストしましたが、修正されました。

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "TestConnection")
            {               
                var FormItem = e.Item as GridDataItem;
                if (FormItem == null)
                    throw new Exception("GridDataItem is null");
                var serverNameTextBox = FormItem.EditFormItem.FindControl("tbServerName") as TextBox;
        }

}
于 2012-12-26T04:53:47.600 に答える
0

これを行う1つの方法は、フィールド値をRadGridデータキー内に格納することです。OnRadGridItemCommandが発生したら、次のような値を取得してみてください。

string tbServerNameValue = RadGridID.MasterTableView.DataKeyValues[e.Item.ItemIndex]["field_name"];

それが正しいsintaxであるかどうかはわかりませんが、現在このコードをテストすることはできません。試してみてください。

于 2011-10-26T13:24:21.033 に答える