如何在asp.net GridView中获取选定行字段 [英] How to get selected row field from gridview in asp.net

查看:117
本文介绍了如何在asp.net GridView中获取选定行字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展与GridView控件一个aspx页面。我在这里我粘贴code

I am developing a aspx page with Gridview control. here i am pasting my code


                        
                        
                        
                        
                        
                        
                        

                    <Columns>

                     <asp:TemplateField HeaderText="Request">
                    <ItemTemplate>
                    <asp:LinkButton ID="sendrequest" runat="server" Text="SendRequest" CommandName="SendRequest"></asp:LinkButton>
                    </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="FirstName">
                    <ItemTemplate>
                    <asp:Label ID="fname" runat="server" Text='<%#Eval("fname") %>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="LastName">
                    <ItemTemplate>
                    <asp:Label ID="lname" runat="server" Text='<%#Eval("lname") %>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="EMailID">
                    <ItemTemplate>
                    <asp:Label ID="email" runat="server" Text='<%#Eval("email") %>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Image">
                    <ItemTemplate>
                    <asp:Image ID="img" runat="server" ImageUrl='<%#Eval("imagepath") %>' Width="100" Height="100" />
                    </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Request">
                    <ItemTemplate>
                    <asp:LinkButton ID="viewprofile" runat="server" Text="ViewFullProfile" CommandName="ViewProfile"
                    a href ='<%#"ViewProfile.aspx?email="+DataBinder.Eval(Container.DataItem,"email") %>'>
                    </asp:LinkButton>
                    </ItemTemplate>
                    </asp:TemplateField>


                    </Columns>



                </asp:GridView>

我的问题是需要其中的LinkBut​​ton(sendRequest将)点击该行的电子邮件值的电子邮件值

My question is i need email value of which LinkButton(SendRequest) clicked that row email value

请帮我

推荐答案

处理GridView的RowCommand事件:

Handle the GridView RowCommand event:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName.Equals("SendRequest")) 
    { 
       string strEmail = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
       lbltest.Text = strEmail; 
    } 
} 

这是假设你有设置的电子邮件的的的DataKeyNames。
您还必须设置的CommandArgument中的 sendRequest将的按钮

that is assuming you have the DataKeyNames set as email. You must also set the CommandArgument of the sendRequest button to

CommandArgument="<%# Container.DataItemIndex %>

这篇关于如何在asp.net GridView中获取选定行字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆