2012-12-19 103 views
0

我是asp.net中的新成員,現在我使用RadControls作爲Asp.net Ajax。我試圖按照Asp.Net GridDemo - 插入/更新/刪除,它似乎並不是所有的工作都很好,所以我做了一些改變,結果做得不錯,但插入按鈕仍然不工作,併爲更新按鈕,它做工精細用一個很小的問題......insert Rad Grid Command Not Working

我有1個視圖viewFacilitiesMaster和2臺tblCity和表tblBranch

在我的radgrid控件我只是想顯示設備,facilityID,城市,cityID ,分支,從視圖中的BranchID。

我使用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][email protected])"> 
      <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

試試這個

集Telerik的網格屬性AllowAutomaticUpdates或AllowAutomaticDeletes或AllowAutomaticInserts真 .. 。

+0

仍然不工作,但請注意,如果我從AddFacility.ascx中刪除此SelectedValue ='<%#DataBinder.Eval(Container,「DataItem.BranchID」)%>',那麼插入帳單工作但編輯時沒有選定的值在這些下拉列表中: –