473,902 Members | 5,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add unbound column to gridview

parshupooja
159 New Member
Hello,
I have a bounded gridview with 14 rows and 6 columns. I want to add a additional column to it named as date and it shd be unbounded. Basically i want to display incremental date in this column such as
06/01/2007
06/02/2007
06/03/2007
06/04/2007
06/05/2007
06/06/2007 and so on

i am using asp.net C#
Plz help
Sep 11 '07 #1
3 13315
nateraaaa
663 Recognized Expert Contributor
Hello,
I have a bounded gridview with 14 rows and 6 columns. I want to add a additional column to it named as date and it shd be unbounded. Basically i want to display incremental date in this column such as
06/01/2007
06/02/2007
06/03/2007
06/04/2007
06/05/2007
06/06/2007 and so on

i am using asp.net C#
Plz help
Use a template column and add a label to this to hold any data that you wish. Then in the code behind use the findcontrol method and assign the text of the label.
Here is a quick example.
[HTML]<asp:GridView id="GridView1" runat="server">
<Columns>
//whatever you already have +
<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label id="lblDate" runat="server"> </asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>[/HTML]

Code Behind:

Expand|Select|Wrap|Line Numbers
  1. for(int i=0; i<GridView1.Rows.Count;i++)
  2. {
  3. //create new label with the contents of lblDate
  4. Label labelDate = (Label)GridView1.Rows[i].FindControl("lblDate");
  5. labelDate.Text = DateTime.Now.AddDays(i);
  6. }

Nathan
Sep 11 '07 #2
parshupooja
159 New Member
thank you for help i shd have posteded my doubt earlie instead of wasting time. ther is only small error in code given by u
Expand|Select|Wrap|Line Numbers
  1. labelDate.Text = DateTime.Now.AddDays(i).tostring();
Use a template column and add a label to this to hold any data that you wish. Then in the code behind use the findcontrol method and assign the text of the label.
Here is a quick example.
[HTML]<asp:GridView id="GridView1" runat="server">
<Columns>
//whatever you already have +
<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label id="lblDate" runat="server"> </asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>[/HTML]

Code Behind:

Expand|Select|Wrap|Line Numbers
  1. for(int i=0; i<GridView1.Rows.Count;i++)
  2. {
  3. //create new label with the contents of lblDate
  4. Label labelDate = (Label)GridView1.Rows[i].FindControl("lblDate");
  5. labelDate.Text = DateTime.Now.AddDays(i);
  6. }

Nathan
Sep 11 '07 #3
nateraaaa
663 Recognized Expert Contributor
thank you for help i shd have posteded my doubt earlie instead of wasting time. ther is only small error in code given by u
Expand|Select|Wrap|Line Numbers
  1. labelDate.Text = DateTime.Now.AddDays(i).tostring();
You are right I forgot the .ToString().

Nathan
Sep 11 '07 #4

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

Similar topics

2
6173
by: Todd | last post by:
Hello, I'm curious if anyone knows of a way (if one exists) to tell a form (in Access 2002 VBA) to sort on an unbound column of a combo box on the form. Here's what I want to do: A combo box on my form contains a category ID (bound column, not visible, long integer) for the items listed on the form and a description (unbound column, visible, string.) I can "Sort Ascending" and "Sort Descending" on the visible description in the...
7
1815
by: Max | last post by:
I've included the needed tables in the DataSource. Those tables that are bound to controls I can workwith. But how do you get access to the DataAdaptors that are not bound? me.Dataset1.table is a table with no Insert or Update methods. pll.DataSet1.table has the Row, ChangeEvent, and ChangeEventHandler. It seems like it should be fairly straight forward to use the DataAdapter without binding it to a control. How do you do this?
1
2972
by: keithb | last post by:
How can I relate data in the bound columns of a GridView control to an unbound checkbox in a template column in the same row? The checkboxes indicate which rows are to be deleted when an update button is clicked. Thanks, Keith
1
3554
by: Eric | last post by:
I have a GridView control that I want to sort on multiple columns when I click a particular column. For example, I display Last name + ", " + First name in the first column and display id in the second column. When clicking on the first column, I want the GridView to sort on LastName and FirstName. Based on Microsoft's documentation of SortExpression property, all I have to do is to set SortExpression=LastName,FirstName on the first column....
1
3527
by: Martin | last post by:
Hi, I'm having a problem with a datagridview control when trying to read the value of an unbound checkbox cell. The code below works fine if I click on any text cell, bound or unbound, and also if I click on a data bound checkbox cell. But it fails with null reference exception if I try to read the value on an unbound cell.
2
5464
by: Greg | last post by:
I have a gridview on my form which I have populated using a datareader. What I would like to do is to be able to remove specified records from the gridview, without affecting the source of the data. I'm a bit confused about how to go about removing the rows - all the google searches I have done so far seem to assume that the grid view is bound and the programmer wants to delete the data from the original source. Is there any easy way to...
1
2713
by: Greg | last post by:
I have a gridview on my form which I have populated using a datareader. What I would like to do is to be able to remove specified records from the gridview, without affecting the source of the data. I'm a bit confused about how to go about removing the rows - all the google searches I have done so far seem to assume that the grid view is bound and the programmer wants to delete the data from the original source. Is there any easy way to...
2
2838
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
19
3948
by: Mel | last post by:
I want to display custom data in some sort of control on a web page. By custom data I mean it's not in a database yet it just resides in a List Box on a different tab . I just want to display the data and allow the user to edit a couple values. What control can I use that will allow me to manually fill it with whatever data I want and allow user editing? (using: asp.net 2.0, vb.net, visual studio 2005, winxp pro sp2)
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10870
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.