2012-03-10 28 views
0

我有我的網格面板如下僅獲得特定值如何從網格面板上選擇行

<ext:GridPanel ID="GridPanel1" runat="server" Height="300" Title="Title"> 
    <ColumnModel runat="server"> 
     <Columns> 
     </Columns> 
    </ColumnModel> 
    <Store> 
     <ext:Store ID="Store1" runat="server" EnableViewState="true"> 
     </ext:Store> 
    </Store> 
    <SelectionModel> 
     <ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="true" runat="server"> 
     </ext:RowSelectionModel> 
    </SelectionModel> 
    <Buttons> 
     <ext:Button ID="btnDelete" runat="server" Text="Delete"> 
      <DirectEvents> 
       <Click OnEvent="Delete"> 
        <ExtraParams> 
         <ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true}))" 
          Mode="Raw" /> 
        </ExtraParams> 
       </Click> 
      </DirectEvents> 
     </ext:Button> 
    </Buttons> 
</ext:GridPanel> 

這是從我的數據庫我的網

enter image description here

這是我的代碼刪除選定的行,但這是循環的行值,因爲我用字典

protected void Delete(object sender, DirectEventArgs e) 
{ 
    string json = e.ExtraParams["Values"]; 
    string value = string.Empty; 
    Dictionary<string, string>[] companies = JSON.Deserialize<Dictionary<string, string>[]>(json); 
    bool addHeader = true; 

    foreach (Dictionary<string, string> row in companies) 
    { 
     if (addHeader) 
     { 
      //sb.Append("<tr>"); 
      foreach (KeyValuePair<string, string> keyValuePair in row) 
      { 
       value = keyValuePair.Value.ToString(); 
       SqlConnection con = new SqlConnection(connection); 
       con.Open(); 
       SqlCommand cmd = new SqlCommand("Delete from Users where Name='" + value + "'", con); 
       cmd.ExecuteNonQuery(); 
       BindData(); 
      } 
      addHeader = false; 
     } 
    } 

}

如果我選擇第一行並單擊刪除,我想刪除該行並重新綁定網格。任何人都可以告訴如何做到這一點。如果用戶沒有使用Java腳本選擇任何行,我也想提醒一個消息框

+0

完全是錯誤的方法來刪除記錄,嘗試其他方法 – sakir 2013-12-26 15:37:10

回答

0

這是ExtJs4嗎?查找網格控件的getSelectionModel()。getSelection()方法。