473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem: Dynamic TemplateFields in GridView

87
I have created a templatefield at runtime for checkboxcolumn in gridview using Itemplate Interface and InstanceIn methods.

I have given the id for checkbox also.

I get the checkbox column in gridview successfully.

Now i want to check all the checkbox in gridview.

But when i find checkbox controls in gridview with respect to the id i have given, it returns me nothing.

Following is the code in InstanceIn method of class GridViewTemplate which Implements Itemplate.

Expand|Select|Wrap|Line Numbers
  1. Select case ListItemType.Item
  2.  
  3.  Case ListItemType.Item
  4.  
  5.   Dim chk as checkbox
  6.   chk=new checkbox
  7.   chk.id="chkSelRoom"
  8.   Container.items.add(chk)
  9.  
  10. End Select
  11.  
Code for Finding Checkbox Control in GridView.
Expand|Select|Wrap|Line Numbers
  1. For each row as GridViewRow in dgvRoomDetails.rows
  2.  
  3.  dim ch as checkbox
  4.  ch=new checkbox
  5.  ch=CType(row.FindControl("chkSelRoom"),checkbox)  // returns nothing
  6.  ch.checked=true  // object reference not set to an instance of the object
  7.  
  8. End For
  9.  
Error are shown as comments in above code.
Mar 17 '10 #1
4 2974
Ananthu
87
Hi,

I have created a dynamic templatefields (checkbox and textbox) for gridview successfully by writing code using ITemplate Interface.

I have loaded the gridview dynamic columns in Form_Load event and also inside the Page.IsPostBack condition only.

I am having checkbox column and textbox column in my gridview when loading a page.

But when I click the button control in that page, the templatefields checkbox and textbox column gets removed and only empty columns are displayed after that. But other columns Bounfields are displayed properly.

What's the problem?

Give me solution for it.

Thanks in advance.
Mar 18 '10 #2
Ananthu
87
I found the answer by myself. The reason is that I should load the dynamic columns of gridview in Page_PreInit event and not in Page_load event. That's it. It worked fine. Now i am able to check all checkbox in gridview by a button click event.
Mar 18 '10 #3
Ananthu
87
Hi,

I found the answer by myself. The reason is that I should load the dynamic columns of gridview in Page_PreInit event and not in Page_load event. That's it. It worked fine. Now the template columns are not disappearing.

Thanks if you have also tried with my posted question.
Mar 18 '10 #4
Frinavale
9,735 Expert Mod 8TB
I'm really happy that you've solved your problem.
I looked at my code that is similar to yours (except that I use link buttons instead of check boxes) and could not think of anything that would explain the problem that you were having.

I should have known it had something to do with where you were dynamically instantiating these controls.

Thanks for sharing your solution!

-Frinny
Mar 18 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a...
2
by: clickon | last post by:
I have set up a GridView control bound to an SQLDataSource control. Depending on which option a user selects in a DropDownList Each datasource is a sethe select command retrieves a list of...
2
by: Will Winn | last post by:
I have a gridview template field that I would like to get the value of during the RowEditing event, but can't figure out how. Here's an example of how I get the value of a cell for the row being...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
1
by: Tor Inge Rislaa | last post by:
Dynamic Articles from a Database Hi, I have a website containing one webform (default.aspx) and a database containing one table (articles) the table contains only 4 field's id, tittles,...
2
by: jph | last post by:
Hello, im starting asp.net coder, just doing my first asp.net test site. Im having problems accessing gridview's autogenerated edit,update, cancel text properties. Gridview itself works fine, i...
2
by: Robert Fernandez | last post by:
I've got a gridview with BoundFields and TemplateFields and a linkbutton with a CommandName="Select". When I click on this linkbutton the TemplateField objects disappear on postback but the...
1
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have a GridView which i can Page on (go to page 2,10,...) the thing is that i have a dynamic query which set the GridView from starts on page 1. the thing is that when i start to go over the...
4
by: beton3000 | last post by:
Hello! I'm building a GridView using code to add template fields, because there is a random number of columns in result set from database. I'm using a class with ITemplate interface for defining...
0
by: edurazee | last post by:
I am able to create BoundFields and Footer-rows dynamically like this in my GridView: protected void Page_Load(object sender, EventArgs e) { CreateGridView(); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.