首页 新闻 会员 周边

asp.net GridView获取控件

0
悬赏园豆:10 [已解决问题] 解决于 2013-05-09 14:07

我用GridView的模板做了一个LinkButton控件和一个Label的控件,我想点击LinkButton获取Label中的Text值,但是不知道怎么才能得到点击的LinkButton的行数,请问该怎么办?

navisl的主页 navisl | 初学一级 | 园豆:185
提问于:2013-05-08 22:53
< >
分享
最佳答案
1

Aspx:

<asp:GridView ID="GridView1" DataKeyNames="id" runat="server" AutoGenerateColumns="false" onrowcommand="GridView1_RowCommand">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" />
                <asp:TemplateField HeaderText="title">
                    <ItemTemplate>
                        <asp:Label ID="LabText" runat="server" Text='<%#Eval("Title") %>'></asp:Label>
                        <asp:LinkButton ID="lbTest" runat="server" CommandName="test" CommandArgument='<%# ((GridViewRow)Container).RowIndex %>'>点击</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

codeBehide:GridView1_RowCommand

int index= Convert.ToInt32(e.CommandArgument.ToString());
Response.Write(((Label)this.GridView1.Rows[index].FindControl("LabText")).Text);


 

收获园豆:10
yyutudou | 小虾三级 |园豆:997 | 2013-05-09 00:11
其他回答(2)
0

if (e.CommandName.Equals("test")) 

  GridViewRow gview = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer; 
  int RowIndex = gview.RowIndex; 

Yu | 园豆:12980 (专家六级) | 2013-05-09 08:46
0

还在用GridView?  你应该还是个学生吧?哈哈 出来你就知道错了哦

小熊vs | 园豆:20 (初学一级) | 2016-08-01 14:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册