当单击行内的按钮时,如何从gridview中获取选定的行 [英] how to get selected row from gridview when button inside that row is clicked

查看:78
本文介绍了当单击行内的按钮时,如何从gridview中获取选定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一列的网格视图.在该列中,我有一个按钮和标签..单击该行中的按钮时,我需要获取特定行的值

-------------------------------------------------- ------------
标签(例如,值= 1)用于预订的按钮



-------------------------------------------------- --------------
标签(例如,值= 2)预订按钮




-------------------------------------------------- -------------


我的网格视图类似于上面的视图.如果我单击任一行中的按钮,我需要获取该行中的label的值.例如,如果我选择第二行中的按钮,则需要获取该值2

I have a grid view with one column.In that column i have one button and label..i need to get the value of a particular row when button in that row is clicked

--------------------------------------------------------------
Label (eg value =1) Button to book



----------------------------------------------------------------
Label (eg value =2) Button to book




---------------------------------------------------------------


My grid view is like the one shown above .If i click on the button in any one of the row i need to get the value of label in that row.For example if i select button in second row i need to get the value 2

推荐答案

您可以尝试:

datagridview.SelectedRows [0] .Cells [列名].Value

列名:输入列或列索引的名称
You can try:

datagridview.SelectedRows[0].Cells[columnname].Value

columnname: Enter the name of the column or column index


在服务器端使用以下代码



use the following code on server Side



Sub GV_Select(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim btn As Button = CType(sender, Button)
    Dim tabelcel As TableCell = CType(btn.Parent, TableCell)
    Dim row As GridViewRow = CType(tabelcel.Parent, GridViewRow)
    Dim s As Integer = CType(row.FindControl("eid"), LinkButton).Text
    MsgBox(s.ToString)
End Sub




然后使用
在客户端调用此代码 正在关注

< gridview>
< column>




Then call this code in the client side using the
following

<gridview>
<column>

<asp:TemplateField>

  <ItemTemplate>

                        <asp:Button OnClick="GV_Select" ID="sel" runat="server" Text="Select"> </asp:Button>
                        <asp:Button OnClick="RedirectPage" ID="eid" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Empid")%>'> </asp:Button>

  </ItemTemplate>
  </asp:TemplateField>


<列>< gridview>



在消息"框中有结果.您可以在任何需要的地方获得结果.确定是否有用?


<column><gridview>



here I have got the result in the Message box.You can get the result where ever You want.Ok is it useful?


这篇关于当单击行内的按钮时,如何从gridview中获取选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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