关于GridView的问题,,
<Columns>
<asp:HyperLinkField DataNavigateUrlFields= "hrefAddress " DataTextField= "hrefDisplay "
Target= "_blank " HeaderText= "网站 " >
<ItemStyle Width= "200px " />
</asp:HyperLinkField>
<asp:HyperLinkField DataNavigateUrlFields= "hrefAddress " DataTextField= "hrefDisplayAll "
Target= "_blank " HeaderText= "介绍 " />
</Columns>
以上是我的部分代码.
请问我如何能够得到GridView中被点击的行??
------解决方案--------------------ASP.net的GridView中实现点击某行的任意位置就选中该行
在 GridView中增加一列:(该列是选择按钮,让其不显示)
<Columns>
<asp:CommandField ShowSelectButton= "True " Visible= "False " />
</Columns>
在GridView的RowDataBound事件中增加以下代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.RequiresJavaScriptProtocol = true;
myPostBackOptions.PerformValidation = false;
String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$ " + e.Row.RowIndex.ToString());
e.Row.Attributes.Add( "onclick ", evt);
}
最后在GridView的SelectedIndexChanged事件中增加你选中了某行后想做的事:
protected void dataGridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//Functions you want to carry out;
}
------解决方案--------------------ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.chs/cpref16/html/E_System_Web_UI_WebControls_GridView_SelectedIndexChanging.htm
------解决方案--------------------添加一个选择列
<Columns>
<asp:CommandField ShowSelectButton= "True " />
</Columns>
后台SelectedIndexChanged里
GridView1.SelectedIndex就是选择的行
------解决方案-------------------- <pages enableEventValidation= "false "/> 就可以了。