表でクリックすると行列の値が得られ、ページが更新されます
4524 ワード
//
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>");