我的网格面板如下
<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>
这是我数据库中的网格
这是我删除所选行的代码,但这是循环的行值,因为我使用了字典
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 :(得分:0)
这是ExtJs4吗?查找网格控件的getSelectionModel()。getSelection()方法。