.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Programmatically added linkbutton disappears from gridview on click

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

I have a gridview with several boundfields and 1 template field that contains a link button. When I click on this link button I want to change one of my bound fields from text to a link button on the affected row. This part works just fine. I click the existing link button and the text in the appropriate field is replaced with a link button. But when I click on the new link button it just disappears. I have been researching this all morning and I believe below are the pertinent facts:

  • I am using the gridview OnRowCommand to capture the link button click and take the appropriate action based on the CommandName
  • I am using the gridview OnRowDataBound to create and add the new link button
  • I am binding the gridview in !IsPostBack

Based off some other posts I read I think that binding the gridview in !IsPostBack is causing the new linkbutton to disappear. How can I fix this? Do I need to add the new linkbutton somewhere other than OnRowDataBound? Do I need to bind the grid somewhere other than !IsPostBack? Am I going about this completely the wrong way?

I am happy to post any of my code, I just was not sure what would be most helpful. I apologize if this has been answered elsewhere. I have found lots of posts with similar situations, but none of them had an answer that I could use.


View Complete Post

More Related Resource Links

Dynamically creating Gridview Template - Linkbutton Click not working



I have written some code to dynamically generate template columns for gridview which works well. However, each cell in the gridview has to be a linkbutton, which when clicked does a db update and redirects to a specific url with some parameters in it.

I have attached a click event handler to the linkbutton in the InstantiateIn method but the event does not seem to fire.

Could someone please help? the code is below -

//Dynamically creating the Grid

protected void btnAnalyze_Click(object sender, EventArgs e)

how to capture value of javascript function called by GridView Linkbutton Click



i have gridview with linkbutton.when i click linkbutton it should call javascript function which returns value would be input for database functions.

how do i capture javascript function retun value(i am using Registerclientscriptblock)? and that should be input for database function.

Inshort i need to call two function from link button click - one javascript function,one ado.net function which will update value in database.

output of javascript function will be input for database function.

function Getlogitudelantitude(address)


return "35.3434343,-74.334343"


Linkbutton_click(object sender,Eventargs e)


register javascript function .. which should return value

string s = "35.34343,-74.334343"

then call database function(s) - does database operation


please reply..



GridView Javascript Click Row and Ajax

This article shows 2 common tasks with the ASP.NET GridView: Binding a List (generic) of objects as DataSource and on clicking a row, getting the values of the selected row by a javascript function. In the example a List with User-objects is displayed. On clicking a row containing the data of a User-object, the Id of the object is used to get the address of the user by an Ajax-call and display it in a details-field.

Alert popup on Gridview Textbox Click

Hi,I am trying to make a Javascript Alert appear when someone clicks on a textbox that is part of a Gridview. the textbox is an Item template and I have an onclick="NotePopup()" in the TextBox properties. I am having trouble grabbing the correct ID of the text box, because it is nested inside a gridview. I have been looking around on Google for a solution but none of the responses are working for me.  The gridview will have multiple rows, so each textbox that could potentially be clicked will have a different ID, is there any way to pass the correct ID to the Javascript, or have the Javascript function grab the correct ID?I did use var Control = '<%= GridView1.ClientID %>';then cut and paste the ID from ViewSource of a textbox and append it to the Control Variable,  to test out the popup and it does workThanks for your helpChris

Gridview and delete option - Button click displays message

Hi, I have a gridview connected to a sql database that allows the user to delete the record. I used the ASP.net automatic "options" for this. However, I would like when the user deletes a record, a message (textbox) appears in the form to say the record has been deleted. Please can anyone provide some sample codes?   Thanks in advance. Nijojo.

Update a field in a gridview to False on a Button Click

 Hi, Ive got a list of records in a gridview (from an SQLDataSource) where a field value is set to True.  I've also added a "reset" button in a template field at the start of the row in the Gridview. What I would like to do is allow the user to click the reset button on a particular row and 'reset' the true value to 'false' (updating the source data). Are there any idiot proof tutorials to do this??? Many thanks for your help! Fiorano

Click event for added RibbonButton in quick access toolbar

Hi! I'm using the new RibbonWindow from Microsoft. When I add a ribbon button to the quick access toolbar at runtime (via right click => add to quick access toolbar) and I click on the button in the quick access toolbar, the associated click event is not fired. It seems, the toolbar makes a copy of the original button, but does not copy the click event handler. How do I detect a click on the newly added button? Thanks! Jus    

Referencing a linkbutton which is within a formview which is within a gridview template

Hello forum.  I have a gridview (gridview1) which contains a formview(formview1) which formview contains a linkbutton(linkbutton1).  I'm trying to  get the linkbutton's click event to redirect to page2 with a querystring value that's the linkbutton's text value. Something like this:   Response.Redirect("~/Page2.aspx" + "?" + "E=" + LinkButton1.Text)How do I reference LinkButton1's text value in code behind so I can pass it to Page2 through the query? Thank you  

Build xml file from gridview values on button click

We are looking to add GoogleMaps to our application. With that said we are going to be using the geocoding api to pass in the lat and long values to pin point locations on the the map. Reading thru the documentation we can pass in the values via XML, so we would like to see how we can take the lat and long values from our gridview and pass that to the API if and when somone clicks on the button to show the map.. The process will work like so, you arrive at the search page, you complete a search, in most if not all cases, you will always get multiple results presented in a gridview. If you should to view them all on the map, you click button and it needs to map out each location on the map. So is there anyway to pull from the gridview the lat, long and description to pass into the API?   Any links to sites that i can review would be great. thanks. 

Chrome update.. Ajaxtoolkit TabContainer disappears on button click.

Hello,Yesterday (Thursday Sep 10th 2010) I was happy to have a TabContainer working fine on a simple page as im learning to use it.On the page was:1) Ajax Script manger.2) 1 command button (it would make label1.text = "hello world"3) A Ajax TabContainer with 2 tabs... 4) Label1 That was it and it was working fine in Chrom and IE Woohoo.. I go home...This morning I load it up to keep working way and doing more with it.... Chrome is my default browser, it loads and I click tab2 then tab 1 all is well.... I click Butto1 and the hole TabContainer disapears..After much dinging I find it still works in IE but that my Chrome has updated (on its own): (I notice only one ICON in Chrome in the uper right corner by the addres bar... Only the Wrench ICON, No more Page ICON.. So I check and sure enough Chrome did a push to V 6.0.472.55.. thanks for asking me Google...) Anyhow thats the difference and now TabContainer goes poof/disappears when clicking a button that refeshes the page.Any thoughts?Others having this problem?ThanksShane 

Keeping Custom properties in GridView Added on OnRowDataBound Event While Sorting

All of my columns are bound in the Gridview. On OnRowDataBound event, I am adding some custom styles like underlines and colors to the text of the columns. Sorting of data is working fine but I am losing my custom styles when I sort. I am using the generic sorting code for the GridView. How I can keep my custom styles on sorting that I added during OnRowDataBound event.   Thanks for your help.


Dim Inko As New InkCanvas         Dim sp As New StylusPoint         With sp             .X = 100             .Y = 100         End With         Dim SPC As New StylusPointCollection         SPC.Add(sp)         Dim DA As New DrawingAttributes         With DA             .Width = 100             .Height = 100             .Color = Colors.Blue         End With         Dim stroke As New Stroke(SPC, DA)         inko.Strokes.Add(stroke)                inko.EditingMode = InkCanvasEditingMode.Ink         inko.DefaultDrawingAttributes = DA WHY THE STROKES ADDED PROGRAMMATICALLY ARE DIFFERENT IN SIZE FROM WHAT IS DRAWN MANUALLY DESPITE THE DRAWING ATTRIBUTES ARE THE S

Send values to parent window on gridview click event


Hello all,

I have a form, which contains 2 textboxes. When i click on the first textbox, i have to open a child window (tool), that contains a gridview control with 2 columns (corresponding to the 2 textboxes). When the user clicks on any row in the gridview, it should send back the 2 column values back to the parent window to the corresponding 2 textboxes. Can anyone help me on how do i achieve this?

I can open the child window and get back the values using window.opener method in JS. 

But can anyone help on how to bind the JS code to the onClick of every row in the gridview. How can i activate the OnClick event of every row/alternating row item of the gridview and bind the JS code and pass each column value to that JS method? The no of columns in the gridview can vary depending upon the data? So in that case, i have to have a collection to be passed to JS code that can contain n number of column values.

Please help.

>>>Click in GridView row item.<<<



I want to click in gridview row ITEM and it will show the result in next page.

For this purpose I used following code in my previous project but the code used in aspx.net.

That is very complicated.

Anyone have idea that how we may write same in vb.net and in which event?

<asp:TemplateField HeaderText="Total Pending">
               <asp:HyperLink ID="Pending_today" runat="server" NavigateUrl='<%# string.Format("PendingToday.aspx?Department={0}&Final_section={1}&Section={2}&Statement_Date={3}&Sr_Date={4}", Server.UrlEncode(Eval("Department").ToString()), Server.UrlEncode(Eval("Final_section").ToString()), Server.UrlEncode(Eval("Section").ToString()), Server.UrlEncode(Eval("Statement_Date").ToString()), Server.UrlEncode(Eval("Sr_Date").ToString()) ) %>' Text='<%#Eval("Pending_today")%>'/>
        <HeaderStyle Width="60px" Wrap="False" />
   <ItemStyle Width="60px" Wrap="False" />
  <ControlStyle Font-Underline="False" ForeColor="Blue&

Help with programmatically set Edit, Update in Gridview


 I'm at the front end of allowing the user to update their data that requires nested gridviews.

I thought I had it set up correctly, but; once I have the grivdiew in Edit mode, when I move the cursor to the first row's textbox, the routine switched out of Edit mode (without a clicking on the Update). I would like to update the data on the screen before the program decides to update the db.

What's causing this?

Here's my aspx page as follows:

<%@ Page Language="VB" AutoEventWireup="false" EnableEventValidation="false" CodeFile="RONs_UPDATING.aspx.vb" Inherits="RONs_UPDATING" %>

<!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>Untitled Page</title>
    <form id="form1" runat="server">
    <div id="div_units" runat="server" style="font-size: medium">
        <asp:GridView ID="gv_x_Units" runat="server" AutoGenerateColumns="False" Style="z-index: 100; left: 110px; position: absolute; top: 10p

How to redirect Infopath form programmatically on button click


I am having an issue with infoPath Forms and C#, 
I have a 1st form open to the user, and when he click a button it opens a 2nd form.

Sounds pretty easy, but I have tried many ways and still error.
(environment is InfoPath Forms 2007 in Sharepoint and code: C#)

this is what I have:
- form1 . a text field where I enter the URL of form2
            . a button with code below

The issue is that if I type the URL of form2 
 in the text field and press the button I get this error
"Critical Error : An error occurred submitting this form to the Web server. The form will now be closed."

But instead of the URL of form2.xsn I type http://www.google.com/ they it works (w

On GridView Click, populate other controls with column values


Hello team,

I have 5 controls on the page - textbox, radiobutton, listbox, checkbox, and any other one more. And i have a grid. The grid has 5 corresponding columns. I have to make the grid row clickable, and on the click, i have to populate my 5 controls with each of the corresponding grid column values.

Please let me know how can i make it. I know that i can make the grid clickable, by setting the e.row.attribute.add("OnClick", "javascript:return passValues();");. In this case, all the value passing will happen in javaScript. Is this the correct way? I have yet to try implementing this, not sure if there will be any issues.

Before that wanted to know if there is any other approach to achieve this. Please help!

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend