我有一个问题,当我定义radgrid时:
<telerik:RadGrid ID="Radgrid" runat="server" RenderMode="Lightweight"
OnNeedDataSource="RadGrid_NeedDataSource"
OnColumnCreated="RadGrid_ColumnCreated"
OnItemCreated="RadGrid_ItemCreated" OnItemDataBound="RadGrid_ItemDataBound"
AllowPaging="true" PageSize="20" PagerStyle-AlwaysVisible="true"
AllowSorting="true"
AutoGenerateColumns="false" AutoGenerateEditColumn="false" OnInsertCommand="Radgrid_InsertCommand">
<GroupingSettings CaseSensitive="false" />
<MasterTableView CommandItemDisplay="Bottom" CommandItemStyle-HorizontalAlign="Right"
EditMode="EditForms" AllowFilteringByColumn="true" EditFormSettings-EditColumn-AndCurrentFilterFunction="Contains">
<Columns>
<telerik:GridBoundColumn DataField="CodEnte" HeaderText="CODICE ENTE" UniqueName="CodEnte" AllowFiltering="true" Visible="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RagioneSociale" HeaderText="RAGIONE SOCIALE" UniqueName="RagioneSociale" AllowFiltering="true" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PartitaIva" HeaderText="PARTITA IVA" UniqueName="PartitaIva" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Pec" HeaderText="PEC" UniqueName="Pec" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Email" HeaderText="EMAIL" UniqueName="Email" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Via" HeaderText="INDIRIZZO" UniqueName="Via" AllowSorting="false" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Comune" HeaderText="COMUNE" UniqueName="Comune" AllowSorting="false" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Provincia" HeaderText="PROVINCIA" UniqueName="Provincia" AllowSorting="false" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Cap" HeaderText="CAP" UniqueName="Cap" AllowSorting="false" AllowFiltering="false" HeaderStyle-Font-Bold="true">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Modifica">
</telerik:GridEditCommandColumn>
</Columns>
<CommandItemSettings
ShowRefreshButton="false" ShowAddNewRecordButton="true" />
<EditFormSettings EditFormType ="Template" EditColumn-AutoPostBackOnFilter="true" EditColumn-ButtonType="FontIconButton">
<FormTemplate>
<asp:Label ID="Label9" runat="server" Text="Cod Ente:" Width="120px" Visible="false"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextCodEnte" Width="200px" EmptyMessage="Cod Ente" Visible="true"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextCodEnte" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label1" runat="server" Text="Ragione Sociale:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextRagioneSociale" Width="200px" EmptyMessage="Ragione Sociale"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextRagioneSociale" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Label ID="Label2" runat="server" Text="Partita Iva:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextPartitaIva" Width="200px" EmptyMessage="Partita Iva"></telerik:RadTextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="PEC:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextPEC" Width="200px" EmptyMessage="PEC"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextPEC" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Label ID="Label4" runat="server" Text="Email:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextEmail" Width="200px" EmptyMessage="Email"></telerik:RadTextBox>
<br />
<asp:Label ID="Label5" runat="server" Text="Via:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextVia" Width="200px" EmptyMessage="Via"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextVia" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Label ID="Label6" runat="server" Text="Comune:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextComune" Width="200px" EmptyMessage="Comune"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextComune" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Label ID="Label7" runat="server" Text="Provincia:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextProvincia" Width="50px" EmptyMessage="Provincia"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextProvincia" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Label ID="Label8" runat="server" Text="CAP:" Width="120px"></asp:Label>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" ID="TextCap" Width="100px" EmptyMessage="CAP"></telerik:RadTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TextCap" ErrorMessage="!" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<telerik:RadButton runat="server" ID="linkInserisci" Width="50px" Text="Inserisci" CommandName="PerformInsert" />
<telerik:RadButton runat="server" ID="linkCancel" Width="50px" Text="Annulla" CommandName="Cancel" OnClick="linkCancel_Click" CausesValidation="false"/>
<br />
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
在前端我看到了:
当我单击INSERISCI按钮时,您可以在FormTemplate中找到,我需要运行一些服务器代码以将值插入到文本框中。这是我的方法:
protected void Radgrid_InsertCommand(object sender, GridCommandEventArgs e)
{
var control = Radgrid;
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
GridDataItem item = e.Item as GridDataItem;
var dataItem = item.DataItem;
}
}
但dataItem为null。我需要将文本值放入FormTemplate中以进行序列化。
答案 0 :(得分:0)
我已根据下面的代码修改了我在我的项目中使用的不同编辑模式。希望它适合你。
然而,Telerik Radgrid是一个非常强大的网格,提供了开箱即用的大部分功能。
您可以从以下网址了解详情:Telerik Embedded mode reference
protected void Radgrid_InsertCommand(object sender, GridCommandEventArgs e) {
var control = Radgrid;
//As Radgrid_InsertCommand is anly used called when insert command performed below condition may be not required
if (e.CommandName == RadGrid.PerformInsertCommandName) {
if (Radgrid.MasterTableView.EditMode == GridEditMode.PopUp || Radgrid.MasterTableView.EditMode == GridEditMode.EditForms) {
// Get inserted item data in popup and embedded edit mode
GridEditableItem ei = ((GridEditableItem)(e.Item));
} else if (Radgrid.MasterTableView.EditMode == GridEditMode.InPlace) {
// Get inserted item data in inline edit mode
GridDataInsertItem ei = (GridDataInsertItem) e.Item.OwnerTableView.GetInsertItem();
}
}
}