Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search


Forms Data Controls :: GridView TemplateField Vanishes On Second Postback With Some Dynamic Content?

(Example code below)

I have a GridView. It has a 'static' TemplateField (in the .aspx page). I add and remove BoundFields to it depending on user preferences on postback. Affter the second postback, the template field appears empty.

Here is a stripped down mockup of what I'm doing. You can click the "Regular Postback" button as much as you want, and nothing bad happens. But if you click the "Recreate" button once-- it's all ok. Click it again, and the "one" column goes on Christmas break.

So is there something else I should be doing, or is this going to be a "halcyon1234 to code interface" error.


View 3 Replies (Posted: Dec 23, 2010 07:50 PM)

Sponsored Links:

Related Forum Messages For ASP.NET category:
Forms Data Controls :: Finding The Dynamic Templatefield Control In A Gridview?
I have a gridview where I in codebehind add a templatefield


In my update command when i try to find the "Result" textbox I get a null object

In the gridview there is another templatefield "Name" that consist of two boundfields("Firstname" and "Lastname") This column is added in the design phase and not in the codebehind.I don't have any trouble finding these controls using the ID added in the markup
[Code]....My issue is with the result column that I add in codebehind.

Posted: Dec 16, 2010 06:48 PM

View 3 Replies!   View Related
Forms Data Controls :: Dynamic Templatefield Disappear During Gridview Rowcommand?
I already implemented the dynamic templatefield which will re-created in every postback.Everytime Imake a postback in the page I see no problem but when I click my imagebutton inside the gridview then the dynamic templatefield disappear.

To double check if it is reallygone at all Ijustselect the second page of the gridview using my customize paging using dropdownlist outside the gridview and the templatefield with its correct data reappear again.

I alreadyput a variable inside the rowcommand to see if the number of columnsare the same with the number of columns the gridview render together with the dynamic templatefield during debugging and it is there but cannot render that templatefield in the client.

Posted: Sep 08, 2010 02:09 AM

View 2 Replies!   View Related
Forms Data Controls :: Static Templatefield In Gridview Disappear On Second Postback?
I have a gridview in which i have declared one static templatefield (with some button ctrls inside) in design itself.

I add the remaining columns to it as a dynamic templatefield by inheriting the ITemplate interface.

My problem is that now when i cause some postback for the firsttime after the Gridview is bounded, it works fine. But when i cause some postback for the second time, all the controls in the static templatefield disappears.

below is my code


Posted: Dec 29, 2010 10:22 AM

View 2 Replies!   View Related
Forms Data Controls :: Gridview With Loginview And Hyperlink Vanishes After Paging?
I have a page that has a gridview which contains a loginview thatcontains hyperlinks with different navigateurls based on the role a user is in.When then page first loads everything displays correctly. However, if there is more that one page of data and the users clicks on a subsequent page, the column with the hyperlinks is blank (the anchor tag gets written out but no href and text) all of the other columns display correctly. If you click the back to page 1 the hyperlink is blank. The only way to get the data to redisplay is to reload the page.

Is this a proper use of the loginview control?

Posted: Jan 07, 2010 05:48 PM

View 5 Replies!   View Related
Forms Data Controls :: Access Dynamic GridView ItemTemplate After Postback?
I have a requirement to use gridview to show and update the information. Here the columns are not fixed, it needs to be dynamically generated. So for this I create a class extending ITemplate and created a ItemTemplate. There is no problem is load the grid, only the big problem is that I am not able to access the controls that are inside ItemTemplate on postback, Even after Init the girdview on postback.

Posted: Jan 30, 2008 06:28 PM

View 5 Replies!   View Related
Forms Data Controls :: GridView W/ Dynamic BoundFields Disappears On Postback In IE Only?
have an 4.0 page containing aGridView, where during the Page_Init event I'm dynamically addingBoundField columns to the gridview. I also have some custom sorting and paging methods that I use with this gridview, which result in postbacks on the page. In Chrome, Firefox, Safari,and Opera the gridview behaves as expected. HOWEVER, in IE 6, 7, or 8when I click to sorta columnin the gridview,orgo to the next page of results in the gridview, it does not bind on postback, returning nothing back to the browser. Again, in anything but Internet Explorer, paging and sorting (frankly any postback event) brings back the gridview in its expected state. I only have the problem in IE. Relevant snippets of my code follow, where you'll see my Page_Init event calling a method in my WebFunctions class to add the BoundField columns for the table I pass to it, and my Page_Load event that calls the method in the user control responsible for binding my dataset to the gridview. Initial page load works in all browsers, but postback loading of the gridview only works in non-IE browsers.


Posted: May 04, 2010 08:12 PM

View 4 Replies!   View Related
Forms Data Controls :: Dynamically Created TemplateField Removed During Postback?
I created a templatefield programmatically and it works fine but whenever I clicked the button inside the gridview and do the postback my templatefield are gone.

Posted: Aug 13, 2010 07:03 AM

View 3 Replies!   View Related
Forms Data Controls :: Viewstate After Postback On Gridview With Dynamic Columns Emplate Fields?
My datasource is an ado data table that I haveconvert to a new data table so thateach row in theoriginal table is now a column with 1 row in my new table. I then bind the new datatable and create dynamic template fields with a text box where I bind the values. My problem is, when I try and retrieve the values changed by the user in the rowcommand event, the template columnsno longer exists.

Does anyone know how i can retrieve these values? I've read over and over that you have to rebind the grid on each postback when you use dynamic templates, but I'm not sure how to do that and retrieve the values entered in the text boxes on the client side.


Posted: Jan 13, 2010 09:28 PM

View 1 Replies!   View Related
How To Gridview Sorting - Column Data Vanishes
I have a Gridview, which I bind to a Dataview programtically. My Gridview has 11 columns. Sorting works fine as long as I do not remove any columns programtically.

In certain cases I remove 2 of the columns from the Gridview. Still not a problem. All the data is properly displayed however the problem occurs when I sort one of the columns. I sort the Dataview and bind to the Gridview again. Data from two of my columns just vanishes. Both of these columns are based on ItemTemplates. The columns are still displayed but just empty cells.

Posted: Aug 18 10 at 19:38

View 1 Replies!   View Related
How To Use Dynamic Columns Boundfield And Templatefield In Gridview
I'm using dynamic columns boundfield and templatefield in gridview, the GV embeded in a panel (autoscroll:auto;width:fixe), I fixed 3 columns to fit the panel's width , when I add exceed the 3 columns the width changes !

Posted: Aug 10th, 2010, 09:10 AM

View 15 Replies!   View Related
Forms Data Controls :: Dynamically Accessing Label In GridView TemplateField During GridView RowDataBound Event?
I have a Label control inside GridView TemplateField.

How can I access it dynamically in GridView RowDataBound event. Can you provide VB code since I'm using VB?

Posted: Mar 01, 2008 09:00 PM

View 5 Replies!   View Related
TemplateField Button Causing GridView Invalid Postback?
I've got a template field in a gridview that contains just a simple button...

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Administration.aspx.cs"
Inherits="Administration" %>
<%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"


Whenever I click the button I get the error...

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I've found a decent amount of articles referencing this issue, including a couple on SO, for example...




I might just be misunderstanding, but as far as I can tell they don't really help me. How do I get this to go away without setting enableEventValidation="false"?

Posted: Jun 3 10 at 17:56

View 2 Replies!   View Related
Forms Data Controls :: How To Sort TemplateField Value In GridView
I want to create simple rating page where player's place,name and rating is displayed. I've created database with ID,Name and Rating Columns, binded Gridview to this database and created TemplateField "Place". With following code I've created numbered list for Place:

protected void Page_Load(object sender, EventArgs e){
for (int i = 0; i < GridView1.Rows.Count; i++)

Posted: Jun 20, 2010 01:11 PM

View 4 Replies!   View Related
Forms Data Controls :: Pulling The Value Of A TemplateField From A GridView?
I have a GridView, bound to atable(Meals) in a SqlDataSource.

Into that GridView, I have added a TemplateField, which contains a DropDownList (which displays the numbers 1 - 10, added manually; no Data Binding). And, I've added a ButtonField.

When I click the Button, I want the values of some of the GridView rows PLUS whatever valuewas selected in the DropDownList to be pulled out and stored in a second Sql table (Orders).

Pulling the rows bound to the SqlDataSource is easy but JavaScript is needed (I think) to pull the SelectedValue from the DropDownList. I understand women more than understand JavaScript (that's how little I know) and the code below has been kindly offered by another forum user who is at a loss, himself, now.

Here's the code and the error message I'm getting.



And here's the Code Behind:


No design time errors reported but here's the run time error:

Object reference not set to an instance of an object.

On the following line:

Line 28: if (row.RowType == DataControlRowType.DataRow)

Posted: Nov 23, 2010 08:51 AM

View 6 Replies!   View Related
Forms Data Controls :: Gridview Add Templatefield Dynamically?


I want to add two image button in the TemplateField.. and add it in the gridview.

Posted: Mar 11, 2011 03:38 AM

View 3 Replies!   View Related
Forms Data Controls :: Dynamically Add A TemplateField To The Gridview?
I have dynamically created my gridview in the codebehind.

All is working correctly.

I now need to dynamically add a TemplateField to the gridview and populate it with a Button.

I have the following code so far:

TemplateField tempField = new TemplateField();
Button btnRemove = new Button();

Posted: Dec 15, 2010 12:59 AM

View 4 Replies!   View Related
Forms Data Controls :: TemplateField In Gridview Not Passing DataKey Value?
I'm relatively new tothe VS environment.I'm using VS2010 Beta2with VB. Ihave a Gridview setup to pull a list of employees. Next to their name I have edit and delete icons.When I leave the icons as ButtonFields, theypass the DataKey value to my code behind perfectly.When I convert theButtonFields to TemplateFields, they no longer pass the DataKey.




Posted: Feb 04, 2010 06:17 PM

View 2 Replies!   View Related
Forms Data Controls :: Programmatically Create Two Way Templatefield In GridView?
I have a programatically generated GridView with a TemplateField in it. I can create the TemplateField and the controls within the TemplateField without an issue. I can also Bind the data from my GridView to the controls in the TemplateField, but only one-way. I'd like the control to also work with the Update command on the GridView.

To bind the data to the control I add an event handler for the DataBinding event, and in that event I use the following code:

ck.Checked = (bool)DataBinder.Eval(row.DataItem, "Queries");

Posted: Nov 12, 2009 04:04 PM

View 1 Replies!   View Related
Forms Data Controls :: Set Value - Label Inside GridView TemplateField
I have problem while set or passing value from code behind to asp:label inside gridView asp:templateField. 1st. I have gridView and using SqlDataSource control for data source. This is my gridView code?


2nd. I have SqlDataSource for my GridView. this is the code :


We can set value in the *.aspx or design view by using <%# bind("str_isi") %> like the asp:label control with ID=lblGvPengumuman but how we can set value in code behind?

Posted: Mar 09, 2011 11:31 AM

View 7 Replies!   View Related
Forms Data Controls :: Sorting Gridview Column Templatefield?
i want to sort a gridview column which is a template field with a repeater control in it. this column has multiple links and i would like to sort using the first link. how can i achieve this.

here is my code:

<asp:TemplateField HeaderText="Groups">

Posted: Jun 16, 2010 04:10 PM

View 2 Replies!   View Related
Forms Data Controls :: Reverse TemplateField Conversion In A GridView?
Though it is usually not a big deal to edit the source code to accomplish this, I am just curious if there is an easier way to reverse the conversionof a column to a TemplateField.The covnersion can be done bya simple click. Is there a similar clickto reverse it?

Posted: Feb 15, 2010 01:46 PM

View 3 Replies!   View Related
Forms Data Controls :: TemplateField With RadioButton Inside A Gridview?
i have a website with a radiobutton inside a gridview, i set the groupname in the gridview but when i run the table, the radiobutton did not became exclusive or i can checked = true on all radiobutton. this is my code:


Posted: Jul 27, 2010 09:05 AM

View 7 Replies!   View Related
Forms Data Controls :: Hiding A Control In A Gridview Templatefield?
I waswondering howto hide a control(lblPrice) in a gridview(Gridview1)'s templatefield, given certain conditions? Like:

If X condition then

-- code to hide lblPrice --

End If

Posted: Feb 11, 2010 01:18 AM

View 6 Replies!   View Related
Forms Data Controls :: Programmtically Set Label In Gridview Templatefield?
I am trying to set the label created in my templatefield during rowbound but I got an error of object reference not set to an instance.

Below is the code for my page.


Posted: Jul 22, 2010 06:25 AM

View 2 Replies!   View Related
Forms Data Controls :: How To Set Font Color In Gridview C# (templatefield)
how to set colors in ESM field if ESM = Elective (Green), Emergency (Red) and Urgent (Purple)

here's my code:

<asp:TemplateField HeaderText="STATUS">
<asp:Label runat="server" ID="lblStatus" ForeColor='??????????' Text='<%# Eval("ESM")%>'

Posted: Dec 13, 2010 11:45 AM

View 7 Replies!   View Related
Forms Data Controls :: Get Datakey From Templatefield (dropdownlist) In Gridview
I have a gridview with a DropDownList (contained in a TemplateField).I have set the OnSelectedIndexChanged event to a function called "ddlAgent_SelectedIndexChanged" This allows me to aquire when a user has changed the value for the dropdownlist. What I need to do is persist this newly selected value to the database for the gridview record. The problem I'm having is how to I get the datakeyNames value for that row? See code below!

TemplateField source
<asp:TemplateField HeaderText="Agent">
<asp:DropDownList ID="ddlAgent" runat="server" AutoPostBack="False" OnSelectedIndexChanged="ddlAgent_SelectedIndexChanged">
<ItemStyle HorizontalAlign="Center"></ItemStyle>

Protected Sub ddlAgent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim gvItems As DropDownList = CType(sender, DropDownList)
' Write the selected Agent ID to the Inquiry record.
'Dim ID As Integer = gvMaint.DataKeyNames(e.SelectedIndex).Value ' THIS FAILS BECAUSE
e.SelectedIndex is not part of System.EventArgs
End Sub

Posted: May 21, 2010 04:43 PM

View 3 Replies!   View Related
Forms Data Controls :: GridView BoundField Vs. TemplateField For Updating?
I have one two GridViews on a page.One Gridview uses BoundFields inside of the GridView and the Update statement works just fine.The other GridView utilizes TemplateFields due to the fact that Validation Expressions have to be used. I also want This GridView to be able to update the vlues when the user clicks on the Update link on the right side of the GridView. The GridView that uses the BoundFields updates just fine, but the GridView that uses TemplateFields will not update. I have checked and everything is correct other than this difference of BoundField and TemplateField.

Posted: Feb 17, 2011 01:16 PM

View 2 Replies!   View Related
Forms Data Controls :: Gridview Templatefield Merge Header?
How can I merge three of thetemplatefields header of gridview?

I want to just merge the header not creating newheader such as "l ModifylPO l Arranging l" --> "l Action l"

Could yougive me the answer for me?

I have some code behind.

--Grid View--

<asp:GridView ID="GridItem" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="itemSql" EmptyDataText="THERE IS NO PROPER ITEM" Width="980px"[code]....

Posted: Dec 03, 2010 10:04 AM

View 10 Replies!   View Related
Forms Data Controls :: Gridview Include Image In Templatefield?
I have a gridview and I want to have a template field. In the template field I want a word over an image. I can get the image in it's own cell with <asp:ImageField DataImageUrlField="IMAGE_URL" > </asp:ImageField>

But I don't know how to access this in a templatefield

Posted: Jan 17, 2011 11:21 AM

View 4 Replies!   View Related
Forms Data Controls :: Create Gridview :TemplateField In Code Behind?

how to create gridview :TemplateField in code behind

Posted: Dec 15, 2010 01:32 PM

View 2 Replies!   View Related
Forms Data Controls :: Adding A Button To A GridView TemplateField?
I have a Gridview with 4 columns bound. I want to add a fifth column with a Button Control that when clicked will display other information based on the selected row.

Everything works fine except for the Button. The fifth column displays with its HeaderText butthe cells areempty. I've tried putting text only, a Label control, a Button control- nothing I put inside the ItemTemplate shows.

One other piece of information: The GridView is inside an UpdatePanel.

The syntax looks correct to me but I must be missing something! Any suggestions??

Below is the basic GridView definition. The only thing that's not working is the TemplateField (marked in bold). All the other cells have the correct data.

<asp:GridView ID="ResourceGrid" runat="server" AllowPaging="true" DataSourceID = "GetBriefResourcesByTag"
AutoGenerateColumns="false" autogenerateselectbutton="true" selectedIndex="1" PageSize="10"
DataKeyNames="ResourceID" onSelectedIndexChanged="ResourceGridView_SelectedIndexChanged"
onDataBound="ResourceGrid_DataBound" Visible="true">


Posted: Dec 02, 2009 10:55 PM

View 3 Replies!   View Related
Forms Data Controls :: User Control In Gridview Dynamically Using Templatefield
I binded user control in gridview dynamically using templatefield (through code behind)

User control consists of 2 textboxes and one dropdown.

There is one button outside the gridview on the form. On click of that button i have to save the values of usercontrol's (child controls i.e textbox and dropdown values) buti am not able to get the values of user controls.

I am able to get User Control using LoadControl and child controls using FindControl but not able get values i am gettingtextbox valuesas blank and dropdown value as 0th selected index even though there is value entered by the user.

Posted: Dec 15, 2010 05:55 PM

View 11 Replies!   View Related
Forms Data Controls :: How To Add Event Handler For Selected Row In Gridview Using TemplateField


I want to add an event handeler that tell me wich row had been selected and highlighted it too. I tried many times, but usually face this error "No overload for 'Grd_ServersInfo_CheckSelectedRow' matches delegate 'System.EventHandler' ". Could any one paste the right code lines to handel this event

Posted: Feb 24, 2011 04:08 AM

View 4 Replies!   View Related
Forms Data Controls :: How To Show / Hide TemplateField Column Of GridView
I am trying to show/hide TemplateField of gridview but not getting it... here is ma sample aspx code

<asp:TemplateField HeaderText="ColumnA">
<asp:Label ID="lblTest" runat="server" Text=' <%# Eval("Test")>'></asp:Label>

Now in server side i am trying to hide this column but failed !!

protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
gv.Columns[2].HeaderStyle.CssClass = "hiddenClass"; // here i am setting display:None using css class

how to show/hide TemplateField on server side

Posted: Feb 19, 2010 12:58 PM

View 5 Replies!   View Related
Forms Data Controls :: Get Gridview Table Values Inside A Templatefield With Vb?
I have a gridview that have some boundfield and a table inside a tamplatefield. That table have 6 input (hidden) that binds when the page load.

How can I get the values of those 6 input inside the table from server side?

I know how to get the boundfield values , with

Dim selectedRow
As GridViewRow = GridDetail.SelectedRow
Dim fName
As String = selectedRow.Cells(1).Text
Dim lName
As String = selectedRow.Cells(2).Text
Dim Iname As
String = selectedRow.Cells(3).Text

all I need is to get the values inside the table.

Part of the Code:



Posted: Jan 21, 2011 05:01 PM

View 4 Replies!   View Related
Forms Data Controls :: How To Use DataNavigateUrlFields In A GridView To Pass The Value Of TemplateField To Another Page
I have a GridViewwith a SQL DB datasource.

I am using a HyperLink Field in the GridView to pass two of the values in each row to another page using DataNavigateUrlFields.

One of those values is straight out of the DB and, if I just pass that, all is well. The other, however,needs to a simple integer (1 - 10) and I've added a TemplateField containing a DropDownList manually populated with these numbers for this purpose.

I keep getting an error saying that the DDL value is not in the DataSource.

How do I add this field/value to the DataNavigateUrlFormatString?

Posted: Nov 17, 2010 03:17 PM

View 7 Replies!   View Related
Forms Data Controls :: Hide LinkButton In TemplateField - On Selecting Gridview Row?
in my girdview i have a template field wihtin linkbutton "Edit". i set the property visible=false


in code behind i set it to visible=true when selecting a row.On selecting an other row - i want to hide the previous linkutton and show the linkbutton in the new selected row

Posted: Mar 15, 2010 02:23 PM

View 5 Replies!   View Related
Forms Data Controls :: Call JavaScript From A LinkButton In A TemplateField In A GridView?
I've turned up lots of advise from similar things, but not this exactly. I have a gridview with a templatefield that I want to call javascript from the OnClick event (or OnClientClick). When I try to compile, it complains saying my server tag isn't well formed. I'm sure that's a red herring...

Posted: Feb 06, 2011 12:52 AM

View 2 Replies!   View Related
Forms Data Controls :: Gridview TemplateField Show String According To Received Data?
What I want to do is to replace number with a name. So if in the Month Column it receives five "1" it changes those 5 "1" to JANUARY.

Is it possible? This is because unfortunately I can only arrange my months by number and not by their name, this because of my queries and tables format, so, I thought maybe I can tell the gridview to change the month number to their relative month name.

Posted: Jul 26, 2010 09:41 PM

View 8 Replies!   View Related
Copyright 2005-08, All rights reserved