我正在努力在插入/更新网格时在我的RadGrid中添加一个ComboBox。所以当我的网格进入editmode时,我希望显示一个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的值来自数据库,所有值都是唯一的。
答案 0 :(得分:0)
在您的代码中,您没有添加Combobox。所以请在EditItemTemplate中添加组合框并尝试以下代码来访问组合框
protected void grid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
RadComboBox combo = ((RadComboBox)item.FindControl("RadComboBoxValore"));
combo.DataSource = SqlDataSource2;
combo.DataValueField = "EmployeeID";
combo.DataTextField = "EmployeeID";
combo.DataBind();
}
}
或添加 GridDropDownColumn