FineUI 官方论坛
标题:
Grid的函数DeleteSeleted()不能正确的删除选中行
[打印本页]
作者:
xhsys
时间:
2015-3-2 13:39
标题:
Grid的函数DeleteSeleted()不能正确的删除选中行
如果GRID是多选,并且是跳空选择行,使用Grid1.DeleteSelected()将出现会把其他没有选择的行删除。我用了下面的方法,才能正确删除。
protected void btnDeleteSelected_Click(object sender, EventArgs e)
{
foreach (int row in Grid1.SelectedRowIndexArray)
{
strCmd = "Update email_recv Set isDel = 1 Where employid = " + Hid_eid.Text + " And emailid = " + Convert.ToString(Grid1.DataKeys[row][0]);
DataSqlServer.DbHelperSQL.ExecuteSql(strCmd);
}
// Grid1.DeleteSelected();
int last = Grid1.SelectedRowIndexArray.Length - 1;
int[] selected = Grid1.SelectedRowIndexArray;
int pos;
for (int i = last; i >= 0; i--)
{
pos = selected[i];
Grid1.Rows.Remove(Grid1.Rows[pos]);
}
}
作者:
zy32002
时间:
2015-3-2 18:22
不是那样删除的,给你段代码
/// <summary>
/// 获取选中行的主id
/// </summary>
/// <param name="grid">FineUI.Grid</param>
/// <param name="keyNumIndex">第几个主键(从0开始)</param>
/// <returns></returns>
protected string GetDataKeysBySelectedRow(FineUI.Grid grid, int keyNumIndex)
{
//需要正确设置grid DataKeyNames主键列名
int[] selections = grid.SelectedRowIndexArray;//获取选中行
if (selections.Length == 0)
{
return "";
}
StringBuilder sb = new StringBuilder();
foreach (int rowIndex in selections)
{
sb.Append("," + grid.DataKeys[rowIndex][keyNumIndex]);//获取每行第keyNumIndex个主键
}
return sb.ToString().Substring(1);
}
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4