我是asp.net的新手,现在我正在为Asp.net Ajax使用RadControls。我试图按照Asp.Net GridDemo - 插入/更新/删除,似乎并不是所有的工作都很好,所以我做了一些改变,结果是做得不错,但插入按钮仍然无法工作,为更新按钮它工作正常,一个非常小的问题......
我有1个视图viewFacilitiesMaster和2个表tblCity和表tblBranch
在我的Radgrid中,我只想从视图中显示设施,facilityID,city,cityID,Branch,BranchID。
我使用Web用户控件作为EditFormType。在我的编辑表单中:AddFacility.ascx。唯一可编辑的区域是设施(radTextbox),城市(dropdownList)和分支(下拉列表)
(注意ddlCity显示酒店城市列表和ddlBranch显示酒店城市相关分支机构)
我的问题是当我点击插入按钮时它不起作用.. -_-,
这是我的代码
frmFacilityMaster.aspx
<telerik:RadGrid ID="gvS" runat="server" DataSourceID="tblFacilities"
GridLines="None" AllowPaging="True" AllowSorting="True"
Width="99%" AutoGenerateColumns="False"
ShowStatusBar="True" OnPreRender="RadGrid1_PreRender"
OnNeedDataSource="RadGrid1_NeedDataSource"
OnUpdateCommand="RadGrid1_UpdateCommand"
OnInsertCommand="RadGrid1_InsertCommand"
OnDeleteCommand="RadGrid1_DeleteCommand" Skin="Black"
ShowGroupPanel="True" onitemcommand="gvS_ItemCommand">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<AlternatingItemStyle BackColor="#E1DED2" />
<MasterTableView autogeneratecolumns="False" datasourceid="tblFacilities"
EditMode="PopUp" commanditemdisplay="Top" >
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<GroupByExpressions>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldAlias="City" FieldName="City" HeaderText="Hotel
City"></telerik:GridGroupByField>
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldName="City"></telerik:GridGroupByField>
</GroupByFields>
</telerik:GridGroupByExpression>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldAlias="Branch" FieldName="Branch" HeaderText="Hotel
Branch"></telerik:GridGroupByField>
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldName="Branch"></telerik:GridGroupByField>
</GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name"
SortExpression="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="NameAr" HeaderText="Name (Ar)"
SortExpression="NameAr" UniqueName="NameAr">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Description" HeaderText="Description"
SortExpression="Description" UniqueName="Description">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Amount" DataType="System.Decimal"
HeaderText="Amount" SortExpression="Amount" UniqueName="Amount">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="cityID" HeaderText="City ID"
SortExpression="cityID" UniqueName="cityID" Visible="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="branchID" HeaderText="Branch ID"
SortExpression="branchID" UniqueName="branchID" Visible="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="facilitiesID" DataType="System.Decimal"
HeaderText="facilitiesID" ReadOnly="True" SortExpression="facilitiesID"
UniqueName="facilitiesID" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
<ItemStyle Font-Italic="True" Font-Underline="True" ForeColor="#CC3300" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn CommandName="find" HeaderText=""
Text="Delete" UniqueName="column">
<ItemStyle Font-Bold="False" Font-Italic="True" Font-Underline="True"
ForeColor="#CC3300" />
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="DescriptionAr" HeaderText="DescriptionAr"
SortExpression="DescriptionAr" UniqueName="DescriptionAr" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="createdDate" HeaderText="Created Date"
SortExpression="createdDate" UniqueName="createdDate" DataFormatString="{0:MM/dd/yyyy}">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="updatedDate" HeaderText="Updated Date"
SortExpression="updatedDate" UniqueName="updatedDate" DataFormatString="{0:MM/dd/yyyy}">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings UserControlName="addFacilityForm.ascx" EditFormType="WebUserControl"
CaptionFormatString=" Add Facility Form" FormStyle-Font-Bold=true >
<FormStyle Font-Bold="True"></FormStyle>
<PopUpSettings Width="70%" />
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings AllowDragToGroup="True">
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
AddFacility.ascx
<table>
<tr>
<td width="25%">
<asp:Label ID="Label2" runat="server" Text=" Hotel City"></asp:Label>
</td>
<td width="75%">
<asp:DropDownList ID="ddlCity" runat="server" DataSourceID="tblCity"
DataTextField="city" DataValueField="cityID" AutoPostBack="true"
SelectedValue='<%#DataBinder.Eval( Container, "DataItem.cityID") %>'
onselectedindexchanged="ddlCity_SelectedIndexChanged" AppendDataBoundItems="true" >
<asp:ListItem Text="Select" Value=""></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="tblCity" runat="server" ConnectionString="<% $ ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="select cityID,city from viewCityAdmin"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td width="25%">
<asp:Label ID="Label3" runat="server" Text=" Hotel Branch"></asp:Label>
</td>
<td width="75%">
<asp:DropDownList ID="ddlBranch" runat="server" DataSourceID="tblBranch"
DataTextField="Branch" DataValueField="BranchID" SelectedValue='<%#DataBinder.Eval( Container, "DataItem.BranchID") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="tblBranch" runat="server" ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="SELECT [BranchID],[Branch] FROM [tblBranch] WHERE ([CityID]=@cityID)">
<SelectParameters>
<asp:ControlParameter Name="cityID" ControlID="ddlCity" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td width="25%">
<asp:Label ID="Label1" runat="server" Text=" Facility"></asp:Label>
</td>
<td width="75%">
<telerik:RadTextBox ID="txtFacility" Runat="server"
Text='<%# DataBinder.Eval( Container, "DataItem.Name" ) %>'
Width="250px">
</telerik:RadTextBox>
</td>
</tr>
</table>
AddFacility.ascx.cs
public partial class addFacilityForm : System.Web.UI.UserControl
{
private object _dataItem = null;
public object DataItem
{
get
{
return this._dataItem;
}
set
{
this._dataItem = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{}
}
答案 0 :(得分:0)
试试这个
设置telerik网格的属性 AllowAutomaticUpdates或AllowAutomaticDeletes或AllowAutomaticInserts为true ...