[英]Selecting a Gridview row without a select column in ASP.NET
我是一个新手,在ASP.NET中是全新的。 我需要在gridview中选择一行,只需单击其中的一行,而不是单击选择行列中的选择按钮。 谢谢 :)
您可以将其添加到代码中,以使任意行的任何单元格都可以选择。
//Select a row by clicking any cells of it
protected void grdEmployeeList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grdEmployeeList, "Select$" + e.Row.RowIndex);
}
}
然后将此页面属性添加到页面设计器的源代码的第一行:
EnableEventValidation = "false"
仅供参考,上面代码中指定的网格引用了我的gridview对象。
只需用您的行填充GridView,就可以了。
是的,你可以这么做。 您不想单击选择按钮,因此使网格中的数据成为链接按钮以显示数据并单击它。 以下是相同的代码
<asp:TemplateField HeaderText="CODE" ShowHeader="true" ItemStyle-CssClass="td" HeaderStyle-CssClass="grid_header"
ItemStyle-BorderWidth="1" ItemStyle-BorderColor="LightGray" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:LinkButton ID="lnkCode" runat="server" Text='<% #Bind("Amm_code") %>' CommandName="Select"
ForeColor="Blue" ToolTip="Click To Edit"></asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="td" />
<HeaderStyle CssClass="td" />
</asp:TemplateField>
我认为您应该为此使用jQuery。
这是一个很好的例子
ASP网络网格视图使用jQuery选择行
这也是一个很好的例子
http://www.codedigest.com/Articles/ASPNET/324_Make_GridView_Row_Selectable_or_Clickable_using_jQuery_in_ASPNet.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.