griview获取当前行的任意一个单元的值

HTML:

<asp:GridView ID="GrvQuerySingInfo" runat="server" AutoGenerateColumns="False" >   
<Columns>
<asp:TemplateField HeaderText="ID" Visible="false">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UserID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LabID" runat="server" Text='<%# Bind("UserID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
 <asp:TemplateField HeaderText="详细" ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="lingk" runat="server" CausesValidation="false" 
                            CommandName="Detail" onclick="lingk_Click">详细</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
 

后台C#:

protected void LingkApply_Click(object sender, EventArgs e)
        {
           GridViewRow gvr = (sender as LinkButton).NamingContainer as GridViewRow;
           if (gvr != null)
           {
               Label user = (Label)gvr.FindControl("LabID");//获取当前行的“LabId”
               Label SignId = (Label)gvr.FindControl("LabSign");
               Label Name = (Label)gvr.FindControl("lblfullname");
               Label date = (Label)gvr.FindControl("labdate");
               string userid = user.Text;
               string datetime = date.Text;
               string name = Name.Text;
               string signid = SignId.Text;
               Response.Redirect("ApplyForSign.aspx?userid=" + userid + "&time=" + datetime + "&type=apply" + "&name=" + name + "&SignId="+ signid);
           }

        }
posted @ 2012-07-27 14:45  偶不是大叔  阅读(260)  评论(0编辑  收藏  举报