Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 18-Nov-12 18:36pm
v2
Comments
[no name] 18-Nov-12 8:07am    
what have you tried so far ?

You can try:

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

columnname: Enter the name of the column or column index
 
Share this answer
 
Comments
spriyanair 18-Nov-12 11:13am    
I have tried that inside rowcommand but that event is not getting fired
Nelek 18-Nov-12 17:07pm    
Please don't think we can read minds or do astral projections to see your monitor. If you need help, the least you could do is to add some relevant code to your question or to explain your problem in such a way, that the users of CP can understand it. Otherwise, nobody will be able to help you.
what have you tried?[^]
After reading the link, please edit your question and add the needed information so people can help you
use the following code on server Side



VB
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



Then call this code in the client side using the
following

<gridview>
<column>
XML
<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>

<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?
 
Share this answer
 
Comments
spriyanair 21-Nov-12 7:27am    
i have tried the following code but its not working.Row command event is not getting fired


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SearchPage.aspx.cs" Inherits="SearchPage" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script runat="server">
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetImages()
{
return new AjaxControlToolkit.Slide[]
{
new AjaxControlToolkit.Slide("images/Blue hills.jpg","Blue Hills",
"Go Blue"),new AjaxControlToolkit.Slide("images/Sunset.jpg","Sunset",
"Setting sun"),new AjaxControlToolkit.Slide("images/Winter.jpg","Winter",
"Wintery..."),new AjaxControlToolkit.Slide("images/Water lilies.jpg",
"Waterlilies", "Lillies in the water"),new AjaxControlToolkit.Slide("images/VerticalPicture.jpg",
"Sedona", "Portrait style picture")};
}
</script>


<link href="StyleSheet.css" rel="stylesheet" type="text/css" />



</head>
<body>
<form id="form1" runat="server">
<div>
           
Displaying Results for
  Country:     
<asp:Label ID="lbl_Country" runat="server" Text="Country">
    
<asp:LinkButton ID="lbt_ChangeFilter" runat="server"
onclick="lbt_ChangeFilter_Click">ChangeFilter
<br />
                                                   
State:          
<asp:Label ID="lbl_State" runat="server" Text="State">




<asp:Panel ID="Panel1" runat="server" Height="1191px" Width="837px">

<br />
<br />

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">



<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"
PageSize="6" Height="500px" Width="800px" BorderColor="White">
<columns>
<asp:TemplateField>
<itemtemplate>
<table align="center" bgcolor="#CCCCCC" class="style1" width= "800px" >
<tr>
<td>
<asp:Label ID="lbl_HotelName" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="#3366FF" Text='<%#Eval("HotelName") %>'>

</td>
<td>
</td>
<td align="right" >
<asp:Button ID="btn_BookHotel" runat="server" OnClick ="btn_Book_Click" Text="Book" BackColor="#990000" ForeColor="White" CommandName="GridButton" CommandArgument='<%# Eval("HotelID") %>' CausesValidation="True" PostBackUrl="~/ReservationPage.aspx" />

</td>
</tr>
</table>
<table align="center" bgcolor="#CCCCCC" width="800px">
<tr>
<td>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900