473,405 Members | 2,282 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,405 software developers and data experts.

add unbound column to gridview

parshupooja
159 100+
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 13262
nateraaaa
663 Expert 512MB
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:TemplateField>
<ItemTemplate>
<asp:Label id="lblDate" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>[/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 100+
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:TemplateField>
<ItemTemplate>
<asp:Label id="lblDate" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>[/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 Expert 512MB
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
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...
7
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...
1
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...
1
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...
1
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...
2
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...
1
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...
2
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...
19
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.