0

我是 asp.net 的新手,我现在正在使用 RadControls for Asp.net Ajax。我尝试按照 Asp.Net GridDemo - Insert/Update/Delete 进行操作,但它似乎对我来说并不是很好,所以我做了一些更改,结果证明做得很好,但插入按钮仍然不起作用更新按钮它在一个非常小的问题上工作正常......

我有 1 个视图 viewFacilitiesMaster 和 2 个表 tblCity 和表 tblBranch

在我的 Radgrid 中,我只想从视图中显示设施、设施 ID、城市、城市 ID、分支、分支 ID。

我使用 Web 用户控件作为 EditFormType。在我的编辑表单中:AddFacility.ascx。唯一可编辑的区域是设施(radTextbox)、城市(下拉列表)和分支(下拉列表)

(注意 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)
    {}
}
4

1 回答 1

0

尝试这个

将 Telerik 网格的属性AllowAutomaticUpdates 或 AllowAutomaticDeletes 或 AllowAutomaticInserts 设置为 true ...

于 2012-12-19T05:42:32.627 回答