473,394 Members | 1,714 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,394 software developers and data experts.

Datagrid cell properties manipulation

js
Question 1:
I have the columns autogenerate = false and add each column
programatically. One of the column is bound to a integer field (Due)
of a recordset. I am trying to change the content of the cell depending
on the value of the bound field. I need to use the following rules to
set the content of the cell. I would appreciate anyone filling the code
comments for needed code. Thanks a million.

private void MyDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
....
....
if ((itemType == ListItemType.AlternatingItem) || (itemType ==
ListItemType.Item))
{
if (strRequester == "Requester1")
{
intDue = (Int32)((DataRowView)e.Item.DataItem)["Due"];
if (intDue < 0)
{
e.Item.ForeColor = Color.White;
if
(((DataRowView)e.Item.DataItem)["SystemDeployed"].GetType().ToString()
== "System.DateTime")
{
e.Item.BackColor = Color.Green;
//need code to set cell content to display "Completed" here...
}
else
{
e.Item.BackColor = Color.Crimson;
//need code to set cell content to display "Over Due" here...
}
}
if (intDue >= 0 && intDue <= 5)
{
e.Item.BackColor = Color.Khaki;
//need code to set cell content to display "Due Soon" here...
}
}
....
....
}

Question 2:
I need to set the width of a column that is bound to a SQL ntext field,
so that this column is always a fixed width diregarding the length of
the context length. I tried the flowing code which is called in the
InitializeComponent(), but the text column width fluctuates.

private void addBoundColumn(string strDataField, string
strHeaderText, string strFieldType)
{
BoundColumn bc = new BoundColumn();
bc.HeaderText = strHeaderText;
bc.HeaderStyle.CssClass = "listHeaderStyle";
bc.HeaderStyle.ForeColor = Color.White;
bc.Visible = true;
bc.DataField = strDataField;
switch(strFieldType)
{
case "Text":
//no sorting on text field
bc.HeaderStyle.Width = Unit.Pixel(100);
bc.ItemStyle.Width = Unit.Pixel(100);
break;
case "DateTime":
bc.SortExpression = strDataField;
bc.DataFormatString = "{0:d}";
break;
default:
bc.SortExpression = strDataField;
break;
}
MyDataGrid.Columns.Add(bc);
}

Nov 19 '05 #1
1 1453
Hi JS,

Suppose it's BoundColumn, you can assign text to it:

e.Item.Cells[col_index].Text = "Completed";

HTH

Elton Wang
el********@hotmail.com
"js" wrote:
Question 1:
I have the columns autogenerate = false and add each column
programatically. One of the column is bound to a integer field (Due)
of a recordset. I am trying to change the content of the cell depending
on the value of the bound field. I need to use the following rules to
set the content of the cell. I would appreciate anyone filling the code
comments for needed code. Thanks a million.

private void MyDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
....
....
if ((itemType == ListItemType.AlternatingItem) || (itemType ==
ListItemType.Item))
{
if (strRequester == "Requester1")
{
intDue = (Int32)((DataRowView)e.Item.DataItem)["Due"];
if (intDue < 0)
{
e.Item.ForeColor = Color.White;
if
(((DataRowView)e.Item.DataItem)["SystemDeployed"].GetType().ToString()
== "System.DateTime")
{
e.Item.BackColor = Color.Green;
//need code to set cell content to display "Completed" here...
}
else
{
e.Item.BackColor = Color.Crimson;
//need code to set cell content to display "Over Due" here...
}
}
if (intDue >= 0 && intDue <= 5)
{
e.Item.BackColor = Color.Khaki;
//need code to set cell content to display "Due Soon" here...
}
}
....
....
}

Question 2:
I need to set the width of a column that is bound to a SQL ntext field,
so that this column is always a fixed width diregarding the length of
the context length. I tried the flowing code which is called in the
InitializeComponent(), but the text column width fluctuates.

private void addBoundColumn(string strDataField, string
strHeaderText, string strFieldType)
{
BoundColumn bc = new BoundColumn();
bc.HeaderText = strHeaderText;
bc.HeaderStyle.CssClass = "listHeaderStyle";
bc.HeaderStyle.ForeColor = Color.White;
bc.Visible = true;
bc.DataField = strDataField;
switch(strFieldType)
{
case "Text":
//no sorting on text field
bc.HeaderStyle.Width = Unit.Pixel(100);
bc.ItemStyle.Width = Unit.Pixel(100);
break;
case "DateTime":
bc.SortExpression = strDataField;
bc.DataFormatString = "{0:d}";
break;
default:
bc.SortExpression = strDataField;
break;
}
MyDataGrid.Columns.Add(bc);
}

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerg | last post by:
The datagrid has a tablestyle applied to it, and there are DataGridTextBoxColumn and each DataGridTextBoxColumn has an array of DataGridTextBox objects. Private Sub highlight(ByVal str As...
0
by: Randy | last post by:
Hello, I have two questions... I have a datagrid. I'm capturing the cell via HitTestInfo. The first question is fairly simple. I'm using an example of how to capture the row/column I found on the...
9
by: Morten | last post by:
Hi! I have a problem displaying some values in a datagrid. I have an array that consists of a number of objects. Each object has 2 properties: Name and a list of web addresses. (e.g: Name:...
2
by: Marty McDonald | last post by:
When setting certain datagrid properties with the IDE (as in the property window), they don't seem to take effect. For instance, Font Name. So I have to set these via code-behind at the cell...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
2
by: fripper | last post by:
After a good bit of urging from folks in this newsgroup I have begun to become familiar with the VB .Net DataGrid control as a replacement for one my favorite VB6 controls ... the FlexGrid. In any...
4
by: Peter | last post by:
(VS 2003) I have a DataGrid and accept button. My problem is when a user starts to edit one of the values in the grid and does not either press Enter or move of the current cell and presses the...
1
by: Arpan | last post by:
The output of a DataGrid is nothing but a HTML table. To color or change the width of the outer 4 borders of a DataGrid, one can use the properties "BorderColor" & "BorderWidth" respectively but...
4
by: Samuel Shulman | last post by:
Hi I added a number of columns to the DataGrid control and I binded them to ceratin columns in the DataView object however I want to fill the URL of the HyperLink type column and I want to add...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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...
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...

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.