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

GridView TemplateField emplty cells

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, AutoGenerateColumns="True".
When I add two columns manually to be able to start drag and drop, the drag and drop works OK, but in GridView1_PreRender() and GridView1_RowCreated() I loose values of GridView1.Rows[i].Cells[2].Text and e.Row.Cells[3].Text, these are "". The e.Row.Cells.Count 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_PreRender() or somewhere else. Can anybody help me?
Thank you in advance.

private void SetTaskCalendar()
{
...

GridView1.DataSourceID = "ObjectDataSource1";
GridView1.DataBind();
...
}

protected void GridView1_PreRender(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
//Overdue Tasks (not Ready and not Accepted)
if ((Convert.ToDateTime(GridView1.Rows[i].Cells[3].Text).Date <= DateTime.Now.Date.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_RowCreated(object sender, GridViewRowEventArgs e)
{
String ID = e.Row.Cells[3].Text;
}


<asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" OnPreRender="GridView1_PreRender"
OnSelectedIndexChanged="GridView1_SelectedIndexCha nged" AllowSorting="True"
OnRowCreated="GridView1_RowCreated" OnSorted="GridView1_Sorted"
EmptyDataText="No Tasks found with te given criteria"
AutoGenerateColumns="True">
<SelectedRowStyle BackColor="#FFC080" />
<EmptyDataRowStyle ForeColor="Blue" />
<Columns>
<asp:TemplateField HeaderText= "Description">
<ItemTemplate>
<div onmousedown='return DayPilotCalendar.dragStart(null, 60*30, "<%# Eval("ID") %>", "");'>
<asp:Label ID="Label1" runat="Server" unselectable='on' Text='<%# Eval("Description") %>'>
</asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "State">
<ItemTemplate>
<asp:Label ID="Label2" runat="Server" Text='<%# Eval("State") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Dec 5 '07 #1
1 1711
Motoma
3,237 Expert 2GB
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
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...
0
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" ...
0
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...
1
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...
0
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...
0
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"...
0
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...
1
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"...
0
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.