Click here to Skip to main content
12,509,464 members (63,626 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET4
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
v2
Comments
Krunal R 18-Nov-12 8:07am
   
what have you tried so far ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can try:

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

columnname: Enter the name of the column or column index
  Permalink  
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
Rate this: bad
 
good
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
    MsgBox(s.ToString)
End Sub


Then call this code in the client side using the
following
  Permalink  
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">

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 | Mobile
Web02 | 2.8.160927.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2016
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