表格中点击获得行列的值、刷新页面

 //行号
int row = ((GridViewRow)((Button)sender).NamingContainer).RowIndex;

 自定义列的显示(参考自csdn.net):

<asp:TemplateField>  
<ItemTemplate>
<asp:Label ID="Label1" runat="server" />
</ItemTemplate>
</asp:TemplateField>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
Label lbl = (Label)e.Row.FindControl("Label1");
switch (drv["字段名"].ToString())
{
case "1" :
lbl.Text = "管理员";
break;
case "2":
lbl.Text = "贵宾";
break;

}
}
}
<asp:TemplateField>  
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# GetTitle(Eval("字段名")) %>'/>
</ItemTemplate>
</asp:TemplateField>

public static string GetTitle(object type)
{
int n = -1;
string title = string.Empty;
if (int.TryParse(type.ToString(), out n)) //考虑到有空值的情况。
{
if (n == 1)
title = "管理员";
else if (n == 2)
title = "贵宾";
}
else
title = "UFO";

return title;
}



Response.Write("<script>window.location.href=window.location.href;</script>"); 



原文地址:https://www.cnblogs.com/oneivan/p/2296573.html