[英]How to get the index of a selected row in row command in asp.net
I want to get the index of the selected row in my grid view.我想在我的网格视图中获取所选行的索引。
This is the command im using on row_command of my gridview这是我在 gridview 的 row_command 上使用的命令
if (e.CommandName == "Select")
{
iCol = gtsk.GetColumnIndexByDBName(grdUser, "UserID");
if (iCol != -1)
{
txtUserName.Text = Server.HtmlDecode(grdUser.Rows[inDx].Cells[iCol].Text.ToString().Trim());
txtUserName.ToolTip = Server.HtmlDecode(grdUser.Rows[inDx].Cells[iCol].Text.ToString().Trim());
}
iCol = gtsk.GetColumnIndexByDBName(grdUser, "UserName");
if (iCol != -1)
{
txtUserName.Text = Server.HtmlDecode(grdUser.Rows[inDx].Cells[iCol].Text.ToString().Trim());
}
iCol = gtsk.GetColumnIndexByDBName(grdUser, "FullName");
if (iCol != -1)
{
txtFullName.Text = Server.HtmlDecode(grdUser.Rows[inDx].Cells[iCol].Text.ToString().Trim());
}
iCol = gtsk.GetColumnIndexByDBName(grdUser, "RoleCode");
if (iCol != -1)
{
ddlRoleUser.SelectedValue = Server.HtmlDecode(grdUser.Rows[inDx].Cells[iCol].Text.ToString().Trim());
}
//iCol = gtsk.GetColumnIndexByDBName(grdUser, "Status");
//if (iCol != -1) { chkActive.Checked = ((CheckBox)grdUser.Rows[inDx].Cells[iCol].Controls[0]).Checked; }
}
You can Use get the index of a selected row on row_command like this您可以像这样使用在 row_command 上获取所选行的索引
int iCol = -1;
int inDx = Convert.ToInt32(e.CommandArgument.ToString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.