Click here to Skip to main content
13,150,607 members (47,646 online)
Rate this:
Please Sign up or sign in to vote.
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 18-Nov-12 1:32am
Updated 18-Nov-12 18:36pm
Krunal R 18-Nov-12 8:07am
what have you tried so far ?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can try:


columnname: Enter the name of the column or column index
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
End Sub

Then call this code in the client side using the

                        <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>


here I have got the result in the Message box.You can get the result where ever You want.Ok is it useful?
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" "">

<html xmlns="">
<head runat="server">

<script runat="server">
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")};

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

<form id="form1" runat="server">
Displaying Results for
<asp:Label ID="lbl_Country" runat="server" Text="Country">
<asp:LinkButton ID="lbt_ChangeFilter" runat="server"
<br />
<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">
<table align="center" bgcolor="#CCCCCC" class="style1" width= "800px" >
<asp:Label ID="lbl_HotelName" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="#3366FF" Text='<%#Eval("HotelName") %>'>

<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" />

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100