2014-07-07 52 views
0

我在.aspx文件中有以下內容。當用戶點擊編輯時,我喜歡它顯示可以更新或取消的表單。目前,當我點擊編輯時,它什麼都不做。請注意,我正在從後面的代碼處理數據源。因此,我沒有對radgrid控件在.aspx文件中數據源:Telerik RadGrid需要編輯模式

這裏是我的代碼:

 <telerik:RadGrid ID="rdClosedLoop" runat="server" GridLines="None" OnDeleteCommand="DeleteClosedLoop" 
       Skin="Metro" ActiveItemStyle-HorizontalAlign="Center" AutoGenerateEditColumn="true" > 
       <MasterTableView EditMode="EditForms" AutoGenerateColumns="False" DataKeyNames="ID" >      
        <RowIndicatorColumn> 
         <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
         <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <Columns>               


          <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" EditFormColumnIndex="0" 
          UniqueName="ID" HeaderStyle-HorizontalAlign="Center"> 
         </telerik:GridBoundColumn>  

         <telerik:GridBoundColumn DataField="ActiveInhibitor" HeaderText="ActiveInhibitor" SortExpression="ActiveInhibitor" EditFormColumnIndex="0" 
          UniqueName="ActiveInhibitor" HeaderStyle-HorizontalAlign="Center"> 
         </telerik:GridBoundColumn>  



         <telerik:GridBoundColumn DataField="Conductivity" HeaderText="Conductivity" SortExpression="Conductivity" EditFormColumnIndex="0" 
          UniqueName="Conductivity" HeaderStyle-HorizontalAlign="Center"> 
         </telerik:GridBoundColumn>                        

         <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"> 
         </telerik:GridButtonColumn> 

        </Columns> 

         <EditFormSettings ColumnNumber="1" CaptionFormatString="Edit for ID {0}" 
       CaptionDataField="ID"> 
       <FormTableItemStyle Wrap="False"></FormTableItemStyle> 
       <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> 
       <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%"> 
       </FormMainTableStyle> 
       <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module" 
        Height="110px" Width="100%"></FormTableStyle> 
       <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
       <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle> 
       <EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"> 
       </EditColumn> 
       <FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle> 
      </EditFormSettings> 

       </MasterTableView> 
       <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True"> 
       </HeaderContextMenu> 
      </telerik:RadGrid> 

後面的代碼:

protected void btnClosedLoop_Click(object sender, EventArgs e) 
    { 
     // Note - verId is based on some conditions 

     var resultCLList = (from ms in db.ver_ClosedLoop 
         where ms.VerificationId == verId 
         select ms).ToList(); 


     rdClosedLoop.DataSource = resultCLList; 
     rdClosedLoop.DataBind(); 

    } 
+0

你的意思是「它什麼都不做」?當你點擊編輯時,沒有編輯窗體打開? – FeliceM

+0

@ FeliceM - 是的,這是正確的。沒有編輯表單打開。我認爲我的問題之一是我沒有使用帶有.aspx文件的數據源。原因是,點擊一個按鈕,我需要產生radgrid,因爲在後面的代碼中,我得到了設置數據源並做了一個數據綁定() –

+0

我不明白你爲什麼不能在標記中使用數據源。你能否詳細說明這一點,以便我可以嘗試提供幫助?你的代碼中的數據源在哪裏? – FeliceM

回答

0

請下面的代碼嘗試片段。

ASPX

<telerik:RadGrid ID="rdClosedLoop" runat="server" GridLines="None" 
     Skin="Metro" ActiveItemStyle-HorizontalAlign="Center" AutoGenerateEditColumn="true" 
     OnItemCommand="rdClosedLoop_ItemCommand"> 
     <MasterTableView EditMode="EditForms" AutoGenerateColumns="False" DataKeyNames="ID"> 
      <RowIndicatorColumn> 
       <HeaderStyle Width="20px" /> 
      </RowIndicatorColumn> 
      <ExpandCollapseColumn> 
       <HeaderStyle Width="20px" /> 
      </ExpandCollapseColumn> 
      <Columns> 
       <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" EditFormColumnIndex="0" 
        UniqueName="ID" HeaderStyle-HorizontalAlign="Center"> 
       </telerik:GridBoundColumn> 
       <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"> 
       </telerik:GridButtonColumn> 
      </Columns> 
      <EditFormSettings ColumnNumber="1" CaptionFormatString="Edit for ID {0}" CaptionDataField="ID"> 
       <FormTableItemStyle Wrap="False"></FormTableItemStyle> 
       <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> 
       <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%"> 
       </FormMainTableStyle> 
       <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module" 
        Height="110px" Width="100%"></FormTableStyle> 
       <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
       <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle> 
       <EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"> 
       </EditColumn> 
       <FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle> 
      </EditFormSettings> 
     </MasterTableView> 
     <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True"> 
     </HeaderContextMenu> 
    </telerik:RadGrid> 

ASPX.CS

protected void Button1_Click(object sender, EventArgs e) 
{ 
    rdClosedLoop.DataSource = getDummyData(0); 
    rdClosedLoop.DataBind(); 
} 

protected DataTable getDummyData(int verId) 
{ 
    // Note - verId is based on some conditions 

    DataTable dt = new DataTable(); 
    dt.Columns.Add("ID",typeof(int)); 
    dt.Rows.Add(1); 
    dt.Rows.Add(2); 
    dt.Rows.Add(3); 

    return dt; 
} 

protected void rdClosedLoop_ItemCommand(object sender, GridCommandEventArgs e) 
{ 
    if (e.CommandName == RadGrid.EditCommandName) 
    { 
     rdClosedLoop.DataSource = getDummyData(0); 
     rdClosedLoop.DataBind(); 
    } 
} 

讓我知道如果任何問題。

相關問題