简体   繁体   English

选择ASP.NET中没有选择列的Gridview行

[英]Selecting a Gridview row without a select column in ASP.NET

Im a newbie and totally new in ASP.NET. 我是一个新手,在ASP.NET中是全新的。 I need to select a row in a gridview by just clicking a row in it and not by clicking a select button from a select row column. 我需要在gridview中选择一行,只需单击其中的一行,而不是单击选择行列中的选择按钮。 Thanks :) 谢谢 :)

You can add this to your code to make the any cells of any row selectable. 您可以将其添加到代码中,以使任意行的任何单元格都可以选择。

//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);
            }
        }

and then add this page attribute to the first line of the source code of the page designer: 然后将此页面属性添加到页面设计器的源代码的第一行:

EnableEventValidation = "false"

FYI the grid specified in the above code refers to my gridview object. 仅供参考,上面代码中指定的网格引用了我的gridview对象。

Just fill in the GridView with your Rows and you're good to go. 只需用您的行填充GridView,就可以了。

Yes you can do that. 是的,你可以这么做。 You don't want to click select button so make your data in the grid a link button to show the data as well as click on it. 您不想单击选择按钮,因此使网格中的数据成为链接按钮以显示数据并单击它。 Following is the code for the same 以下是相同的代码

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM