在插入/更新我的网格时,我正在努力在我的 RadGrid 中添加一个 ComboBox。因此,当我的网格进入编辑模式时,我希望显示一个 ComboBox。
这是我的 aspx 页面:
<telerik:radgrid id="radManageMembers" runat="server" cssclass="GridView" width="96%"
autogeneratecolumns="true" onUpdateCommand="radManageMembers_UpdateCommand" Skin="WebBlue"
onNeedDataSource="radManageMembers_NeedDataSource" OnDeleteCommand="radManageMembers_DeleteCommand"
OnInsertCommand="radManageMembers_InsertCommand" OnItemCreated="radManageMembers_ItemCreated" OnItemCommand="radManageMembers_ItemCommand">
<MasterTableView EditMode="InPlace" AutoGenerateColumns="false"
TableLayout="Fixed" DataKeyNames="MemberID" CommandItemDisplay="TopAndBottom" Skin="WebBlue">
<Columns>
<telerik:GridBoundColumn DataField="MemberID" Display="false">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn" CommandName="Delete" ButtonType="PushButton" Text="Delete">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="MemberName" UniqueName="MemberName" HeaderText="MemberName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="FirstName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="LastName" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Title" UniqueName="Title" HeaderText="Title">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AdditionalNumber" UniqueName="AdditionalNumber" HeaderText="AdditionalNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Telephone" UniqueName="Telephone" HeaderText="Telephone">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="IDNumber" UniqueName="IDNumber" HeaderText="IDNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BusinessName" UniqueName="BusinessName" HeaderText="BusinessName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Email" UniqueName="Email" HeaderText="Email">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LanguageCode" UniqueName="LanguageCode" HeaderText="LanguageCode">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn ButtonType="PushButton" UniqueName="EditCommandColumn">
<HeaderStyle Width="85px"></HeaderStyle>
</telerik:GridEditCommandColumn>
</Columns>
<EditFormSettings CaptionFormatString="Edit details for employee with ID {0}" CaptionDataField="EmployeeID">
<FormTableItemStyle Width="100%" Height="29px"></FormTableItemStyle>
<FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2"></FormTableStyle>
<FormStyle Width="100%"></FormStyle>
<EditColumn ButtonType="ImageButton">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
</ClientSettings>
我知道您必须使用 ItemCreated 事件,但我无法让它完全正常工作。
这就是我在 ItemCreate 中的内容,但这段代码不起作用:
if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridCommandItem)
{
GridCommandItem insertItem = (GridCommandItem)e.Item;
RadComboBox combo = (RadComboBox)insertItem.FindControl("Title");
}
我看过这里的例子 - http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx
但是这个 ComboBox 并没有从数据库中填充不同的值,似乎有重复项,我觉得在 ComboBox 中毫无意义。
我愿意看看是否有其他方法可以做到这一点或解决这个问题的正确方法。
编辑
ComboBox 的值来自数据库,并且所有值都是唯一的。