Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在单击同一行中的按钮时读取该行的数据_Asp.net_Datagridview - Fatal编程技术网

Asp.net 如何在单击同一行中的按钮时读取该行的数据

Asp.net 如何在单击同一行中的按钮时读取该行的数据,asp.net,datagridview,Asp.net,Datagridview,我将数据显示在网格中,如下所示: 开始日期结束日期按钮 2013年3月16日2013年3月17日注册--->这是一个ASP按钮 2013年3月18日2012年3月19日注册---->这是一个ASP按钮 20/3/2012 20/3/2012注册---->这是一个ASP按钮 我想要asp.net和c代码当我点击第一行注册按钮时,我想要得到第一行的数据。如果单击第二行,我只需要第二行开始日期和结束时间的数据。我怎样才能做到这一点?请在这方面告诉我。在asp按钮中,设置属性:CommandName=“

我将数据显示在网格中,如下所示:

开始日期结束日期按钮

2013年3月16日2013年3月17日注册--->这是一个ASP按钮

2013年3月18日2012年3月19日注册---->这是一个ASP按钮

20/3/2012 20/3/2012注册---->这是一个ASP按钮


我想要asp.net和c代码当我点击第一行注册按钮时,我想要得到第一行的数据。如果单击第二行,我只需要第二行开始日期和结束时间的数据。我怎样才能做到这一点?请在这方面告诉我。

在asp按钮中,设置属性:CommandName=“SignUp”CommandArgument=''

现在,单击此按钮将调用Gridview的RowCommand事件

在这种情况下,e.CommandArgument包含您的行号

GridViewRow gvr=gvLinkImages.Rows[e.CommandArgument]

现在您可以使用gvr.Cells[列编号]获取特定文本(不推荐) 或者使用findcontrol获取开始/结束日期的标签或文字(假设您使用的是Templatefields) 下面是示例代码

C#

ASPX

    <asp:GridView runat="server" ID="gvResults" AutoGenerateColumns="false" OnRowCommand="gvResults_RowCommand">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Literal runat="server" ID="lblStartDate" Text='<%#Container.DataItem.StartDate%>'></asp:Literal>

            </ItemTemplate>

        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Literal runat="server" ID="lblStartDate" Text='<%#Container.DataItem.EndDate%>'></asp:Literal>

            </ItemTemplate>

        </asp:TemplateField>
          <asp:TemplateField>
            <ItemTemplate>
                <asp:Button runat="server" ID="btnSignUp" CommandName="SignUp" CommandArgument="<%# Container.DataItemIndex %>"  />

            </ItemTemplate>

        </asp:TemplateField>
    </Columns>

</asp:GridView>


您能否提供页面代码的外观,以确保得到正确的答案?我尝试了ebelow,工作原理如下:(e.CommandName==“SignUp”){GridViewRow=(GridViewRow)((Control)e.CommandSource).NamingContainer;StartDate=DateTime.Parse(row.Cells[0].Text);EndDate=DateTime.Parse(row.Cells[1].Text);Control ctl=e.CommandSource作为控件;
    <asp:GridView runat="server" ID="gvResults" AutoGenerateColumns="false" OnRowCommand="gvResults_RowCommand">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Literal runat="server" ID="lblStartDate" Text='<%#Container.DataItem.StartDate%>'></asp:Literal>

            </ItemTemplate>

        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Literal runat="server" ID="lblStartDate" Text='<%#Container.DataItem.EndDate%>'></asp:Literal>

            </ItemTemplate>

        </asp:TemplateField>
          <asp:TemplateField>
            <ItemTemplate>
                <asp:Button runat="server" ID="btnSignUp" CommandName="SignUp" CommandArgument="<%# Container.DataItemIndex %>"  />

            </ItemTemplate>

        </asp:TemplateField>
    </Columns>

</asp:GridView>