ASP.net 中Gridview控件没有单击处理,代替单击处理,以下两种方法可以处理。
(1)用SelectedIndexChanged事件
HTML Code
C# Code
(1)用SelectedIndexChanged事件
HTML Code
<asp:CommandField ButtonType="Button" HeaderText="添加" ShowHeader="True" SelectText="Add" ShowSelectButton="True">
<HeaderStyle Width="1%" Wrap="False" />
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
<HeaderStyle Width="1%" Wrap="False" />
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
C# Code
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//相关处理
}
{
//相关处理
}
(2)在databound里添加行的js脚本,实现跳转。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
e.Row.Attributes.Add("onclick", "Url('" + this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString().Trim() + "')");
}
}