473,851 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView TemplateField emplty cells

1 New Member
Dear GridView Experts!
I have problems with GridView when adding a column using TemplateField.
I fill GridView1 from a stored procedure. It has a Select statement and returns 14 columns, AutoGenerateCol umns="True".
When I add two columns manually to be able to start drag and drop, the drag and drop works OK, but in GridView1_PreRe nder() and GridView1_RowCr eated() I loose values of GridView1.Rows[i].Cells[2].Text and e.Row.Cells[3].Text, these are "". The e.Row.Cells.Cou nt gives the correct 16, but the cells are "". It is strange, that the grid appears correctly with all the values.
My problem is that I need to set colors based on the Status and Date fields in GridView1_PreRe nder() or somewhere else. Can anybody help me?
Thank you in advance.

private void SetTaskCalendar ()
{
...

GridView1.DataS ourceID = "ObjectDataSour ce1";
GridView1.DataB ind();
...
}

protected void GridView1_PreRe nder(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows. Count; i++)
{
//Overdue Tasks (not Ready and not Accepted)
if ((Convert.ToDat eTime(GridView1.Rows[i].Cells[3].Text).Date <= DateTime.Now.Da te.Date) &
(GridView1.Rows[i].Cells[2].Text != "Ready") && (GridView1.Rows[i].Cells[2].Text != "Accepted") )
{
GridView1.Rows[i].ForeColor = System.Drawing. Color.Red;
}
//Ready Tasks
if (GridView1.Rows[i].Cells[2].Text == "Ready") GridView1.Rows[i].ForeColor = System.Drawing. Color.Green;
}
}

protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
String ID = e.Row.Cells[3].Text;
}


<asp:GridView ID="GridView1" runat="server" AutoGenerateSel ectButton="True " OnPreRender="Gr idView1_PreRend er"
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged" AllowSorting="T rue"
OnRowCreated="G ridView1_RowCre ated" OnSorted="GridV iew1_Sorted"
EmptyDataText=" No Tasks found with te given criteria"
AutoGenerateCol umns="True">
<SelectedRowSty le BackColor="#FFC 080" />
<EmptyDataRowSt yle ForeColor="Blue " />
<Columns>
<asp:TemplateFi eld HeaderText= "Descriptio n">
<ItemTemplate >
<div onmousedown='re turn DayPilotCalenda r.dragStart(nul l, 60*30, "<%# Eval("ID") %>", "");'>
<asp:Label ID="Label1" runat="Server" unselectable='o n' Text='<%# Eval("Descripti on") %>'>
</asp:Label></div>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText= "State">
<ItemTemplate >
<asp:Label ID="Label2" runat="Server" Text='<%# Eval("State") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
Dec 5 '07 #1
1 1747
Motoma
3,237 Recognized Expert Specialist
mghihor,
Welcome to The Scripts. It appears you inadvertently posted your question to the .NET Articles section of our site. I have taken the liberty of moving it to the .NET Forum, as that is the appropriate place to post questions.
Good luck with your problem,
Motoma
Dec 5 '07 #2

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

Similar topics

3
6226
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign if it is in front of the value? My guess would be to use a template column but I dont know how to go about this. Any ideas? Below is an example of what the data looks like raw from the database: $456.95 200.89
0
1454
by: Hongbo | last post by:
Hi, I have a GridView like this one: == <asp:gridview runat="server" id="gvCategory" allowpaging="true" allowsorting="true" alternatingrowstyle-backcolor="#B9DFC7" autogeneratecolumns="false" pagesize="20" width="550px" datasourceid="prodList"> <headerstyle backcolor="#B9DFC7" /> <columns> <asp:templatefield>
0
5242
by: danc | last post by:
I am trying to modify the layout of a row based on the value in some data (I am creating a subtotal line). This works fine when the page is first loaded, but when it's reloaded, the wrong column is restored. <asp:GridView ID="grdvOrder" runat="server" AutoGenerateColumns="False" OnRowCommand="grdvOrder_RowCommand" OnRowDataBound="grdvOrder_RowDataBound" OnRowCreated="grdvOrder_RowCreated"> <Columns> <asp:TemplateField...
1
7882
by: Mike P | last post by:
When you use a SqlDataSource to hook up data to a GridView it seems to be to be very inflexible. For example, I want to create my own Delete button with my own code and I also want to create a popup warning for the user before delete takes place. Whenever I do this with a SqlDataSource, I get the error 'Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified.' Which means I have to specify a sproc or...
0
8569
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row and add child grid into that row because the columns in child grid are same as parent grid and we want to align them with the cols of parent grid. 2. If there is data for child grid we show a plus image in the parent row (in the row above the...
0
2483
by: Mike P | last post by:
I am trying to edit a gridview while using paging, but whenever I try to edit a row on a page other than page 1, I get an error. Here is my gridview and my code : <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="UserKey" AllowSorting="True" HeaderStyle-Height="24px" AutoGenerateColumns="false" SkinID="Grey3" EditRowStyle-CssClass="dgedit"
0
2401
by: den 2005 | last post by:
Hi everybody, I created a Gridview with a TemplateField and there is Label control in ItemTemplate and a DropdownList control in EditItemTemplate, I was to displayed them ok when I click the Edit Command button. But when I about to get the value of this template field I get an empty string value. I check the following the local dtFiles has data and the cells are visible at stage right before foreach GridViewRow gr in gdvFiles.Rows) loop....
1
10411
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID" OnRowCreated="ContactHistoryGrid_RowCreated" CssClass="GridViewTable" GridLines="None" CellSpacing="1" CellPadding="3" AllowSorting="True" AllowPaging="True"> <EmptyDataTemplate>
0
1814
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select button for each row so that the the user can choose a row and the values will be added to a shopping cart. My problem is that the page loads fine and everything is showing as it should be. However, when I select a row the dropdownlist for that row...
0
9897
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9747
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
11019
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...
1
10728
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10356
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9506
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7906
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
5736
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
5933
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.