Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Datagrid control

Reply
Thread Tools

Datagrid control

 
 
Paul
Guest
Posts: n/a
 
      04-28-2004
I have a datagrid I want to change the color of the datagrid row dependant
upon the contents of the data in the row after I bind it to the dataset.

Any hints to how to do this would be appreciated.

Thanks


 
Reply With Quote
 
 
 
 
=?Utf-8?B?aGFyb2xk?=
Guest
Posts: n/a
 
      04-28-2004
this may help

public static void SetDataGridColors(ref DataGrid dg)
{
int itemCount = dg.Items.Count;
for(int 1=0;1<itemCount;i++)
{
string myCellValue = dg.Items[i].Cells[0].Text();
switch(myCellValue)
{
case "this value"
dg.Items[i].BackColor = System.Drawing.Color.Red;
break;
case "that value"
dg.Items[i].BackColor = System.Drawing.Color.White;
break;
}
}
}

this will change the color of the entire row based on the value of the 1st cell in each row.
Remember the cells collection of the datarow is 0 based

if you want to change only one cell in the row a second loop will be needed on the cells collection in the datagrid items loop

hth
Harold

 
Reply With Quote
 
 
 
 
=?Utf-8?B?aGFyb2xk?=
Guest
Posts: n/a
 
      04-28-2004
sorry paul

You call it by sending the completed grid to it.
It does not have to be on ItemDataBound event of the grid, as our helpful friend Diogo said, but it does have to be after it is databound. You may want to change the color of things in the grid if you have edits to the grid without rebinding. This will fire on postback and the ItemDataBound only fires when it's bound up
Like

datagrid1.DataBind()

SetGridColors(ref datagrid1


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can we use dropdownlist control in Datagrid control? Bhuwan Bhaskar ASP .Net 2 10-04-2007 06:09 PM
Composite Control Question: Re-creating DataGrid child control upon Postback? debartsa ASP .Net Building Controls 1 04-23-2004 12:33 AM
Composite Control not receiving DataGrid (child control) events? debartsa ASP .Net Building Controls 0 04-19-2004 08:12 PM
Control derived from datagrid, problem with adding other control and databinding (VB) Jc Morin ASP .Net Building Controls 1 12-05-2003 07:22 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57