如何在 asp.net 中的行命令中获取选定行的索引
How to get the index of a selected row in row command in asp.net
我想在我的网格视图中获取所选行的索引。
这是我在我的 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; }
}
您可以像这样在 row_command 上使用获取选定行的索引
int iCol = -1;
int inDx = Convert.ToInt32(e.CommandArgument.ToString());
我想在我的网格视图中获取所选行的索引。
这是我在我的 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; }
}
您可以像这样在 row_command 上使用获取选定行的索引
int iCol = -1;
int inDx = Convert.ToInt32(e.CommandArgument.ToString());