C# Asp.net Webforms GridView在行上单击

C# Asp.net Webforms GridView在行上单击,c#,asp.net,gridview,webforms,C#,Asp.net,Gridview,Webforms,我正在尝试做一件事,因此,当我单击GridView行时,我想发送CommandArgument,现在,我正在使用linkbuttons,我想摆脱它,我希望用户只单击该行,然后它发送commanaArgument 目前,这是我的代码: <asp:GridView ID="jj" runat="server" AllowPaging="true" AllowSorting="false" AutoGenerateColumns="false" CssClass

我正在尝试做一件事,因此,当我单击GridView行时,我想发送CommandArgument,现在,我正在使用linkbuttons,我想摆脱它,我希望用户只单击该行,然后它发送commanaArgument

目前,这是我的代码:

 <asp:GridView ID="jj" runat="server" AllowPaging="true" AllowSorting="false"
                AutoGenerateColumns="false" CssClass="mGrid" GridLines="None" PagerStyle-CssClass="pgr"
                AlternatingRowStyle-CssClass="alt" OnPageIndexChanging="gridView_PageIndexChanging" PageSize="10" EmptyDataText="Não existem dados para mostrar">

                <Columns>    
                    <asp:TemplateField HeaderText="Pré Ordens">
                                <ItemTemplate>
                                    <asp:LinkButton ID="PreOrdens" OnClientClick="ddd();" onClick="SEND_ID_REGISTO" CommandArgument = '<%# Eval("ID_REGISTO_BASE") %>' Text='<%# Eval("TIPO_Registo") %>' runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                     <asp:TemplateField HeaderText="Descrição do Erro">
                                <ItemTemplate>
                                    <asp:LinkButton ID="DescricaoErro" OnClientClick="ddd();"  onClick="SEND_ID_REGISTO" CommandArgument = '<%# Eval("ID_REGISTO_BASE") %>' Text='<%# Eval("Erro") %>' runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                    <asp:TemplateField HeaderText="NUV">
                                <ItemTemplate>
                                    <asp:LinkButton ID="NUV" OnClientClick="ddd();"  onClick="SEND_ID_REGISTO" CommandArgument = '<%# Eval("ID_REGISTO_BASE") %>' Text='<%# Eval("NUV") %>' runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                    <asp:TemplateField HeaderText="TV">
                                <ItemTemplate>
                                    <asp:LinkButton ID="ErroID" OnClientClick="ddd();" onClick="SEND_ID_REGISTO" CommandArgument = '<%# Eval("ID_REGISTO_BASE") %>' Text='<%# Eval("TV") %>' runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                </Columns>
            </asp:GridView>

这不是完整的代码,只是必要的,但是的,我需要在行上发送命令参数,而不是在链接按钮上单击。

必须使用GridView的RowCreated事件,并且必须在每次回发时添加此事件

比如说

protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) {
        e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
        e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
        e.Row.ToolTip = "select row";
        e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
    }
}
可能重复的
protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) {
        e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
        e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
        e.Row.ToolTip = "select row";
        e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
    }
}