Jot Dhaliwal
Jot Dhaliwal

Reputation: 1500

Get id of the next column in Gridview

enter image description hereenter image description here

I have to get the ID attribute of the Column to COPY & Paste column on click of the Getform column.. Here is code for the GetForm Click

  <asp:LinkButton ID="LnkGet" OnClientClick="GetID();" runat="server" 
          CommandName="GetUrl" Font-Underline="False">Get Form</asp:LinkButton>

JS Code:-

 function GetID() {
     //Do something here
     // console.log(a);
  }

Please guide me a line

Upvotes: 0

Views: 157

Answers (2)

Rahul Singh
Rahul Singh

Reputation: 21795

Since ASP.NET Gridview is rendered as HTML table, you can simply use the closest & next method of jQuery to find the text:-

Assign a class to your LinkButton:-

<asp:LinkButton ID="LnkGet" CssClass="clsLnkGet" runat="server" CommandName="GetUrl" 
     Font-Underline="False">Get Form</asp:LinkButton>

Simply write the event handler with jQuery:-

$('.clsLnkGet').click(function(){
     var td = $(this).closest('td').next();
     var UrlToCopyPaste = $('input[type="text"]', td).val();
     alert(UrlToCopyPaste);
 }); 

Upvotes: 1

Anoop B.K
Anoop B.K

Reputation: 1478

May be this help you....

    <asp:LinkButton ID="LinkButton1" onclick="LinkButton1_Click"" runat="server" CommandName="GetUrl" Font-Underline="False">Get Form</asp:LinkButton>

asp.net code

protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
GridViewRow grv = (GridViewRow)btn.NamingContainer;
string id = grv.Cells[0].Text;
}

Upvotes: 0

Related Questions