if (ds.Tables[0].Rows.Count > 0)
{
dv = ds.Tables[0].DefaultView;
GridView1.DataSource = dv;
GridView1.DataBind();
}
now what i want to do is this. i need to get the value of each cell. if the value is lower than zero, i need to set the font color to RED. how can i do this? i'm practically new to asp.net
ArchangelOfD...
Member
30 Points
8 Posts
Gridview cell value
Nov 02, 2006 02:00 AM|LINK
hey. i have this.... DataView dv = new DataView();
DataSet ds = new DataSet();
ds = kdata.GetData("spRufosGetPlayerHistoricBetList", obj, EntryType.NormalType);
if (ds.Tables[0].Rows.Count > 0)
{
dv = ds.Tables[0].DefaultView;
GridView1.DataSource = dv;
GridView1.DataBind();
}
now what i want to do is this. i need to get the value of each cell. if the value is lower than zero, i need to set the font color to RED. how can i do this? i'm practically new to asp.net
thanks in advance for the help!
jessjing
Contributor
4392 Points
872 Posts
Re: Gridview cell value
Nov 02, 2006 02:47 AM|LINK
hi,
here
if(int.Parse(GridView1.Rows[index].Cells[index].Text)<0)
{
GridView1.Rows[index].Cells[index].ForeColor=System.Drawing.Color.Red;
}
ArchangelOfD...
Member
30 Points
8 Posts
Re: Gridview cell value
Nov 02, 2006 04:18 AM|LINK
i'll try that out then i'll get back to you. thanks for the fast reply. i really appreciate it!!
enjaya
Member
20 Points
4 Posts
Re: Gridview cell value
Nov 02, 2006 08:22 AM|LINK
what jessjing told is right .
but that code needs to be added in RowDataound Event handler of gridview
ArchangelOfD...
Member
30 Points
8 Posts
Re: Gridview cell value
Nov 06, 2006 07:20 AM|LINK
tried your code.. why won't it work with me? now the gridview isn't even showing... i don't understand..
DataView dv = new DataView();
DataSet ds = new DataSet();
object[] obj = new object[] { rogers.GUID, dtStart, dtEnd, catType, marketType };
ds = kdata.GetData("spRufosGetPlayerHistoricBetList", obj, EntryType.NormalType);
try
{
if (ds.Tables[0].Rows.Count > 0)
{
dv = ds.Tables[0].DefaultView;
if (Convert.ToInt32(GridView1.Rows[0].Cells[6].Text)== 0)
GridView1.Columns[6].ItemStyle.ForeColor = System.Drawing.Color.Red;
else
GridView1.Columns[6].ItemStyle.ForeColor = System.Drawing.Color.Black;
GridView1.Columns[4].FooterText = "Total on this page:<br>Overall Total:";
GridView1.Columns[4].FooterStyle.HorizontalAlign = HorizontalAlign.Right;
GridView1.Columns[5].FooterText = dv.Table.Rows[0]["totalStake"].ToString() + "<br>" + dv.Table.Rows[0]["alltotalStake"].ToString(); ;
GridView1.Columns[5].FooterStyle.VerticalAlign = VerticalAlign.Top;
GridView1.Columns[5].FooterStyle.HorizontalAlign = HorizontalAlign.Right;
GridView1.Columns[6].FooterText = dv.Table.Rows[0]["totalnetwinnings"].ToString() + "<br>" + dv.Table.Rows[0]["alltotalnetwinnings"].ToString(); ;
GridView1.Columns[6].FooterStyle.VerticalAlign = VerticalAlign.Top;
GridView1.Columns[6].FooterStyle.HorizontalAlign = HorizontalAlign.Right;
GridView1.DataSource = dv;
GridView1.DataBind();
GridView1.Visible = true;
}
else
{
GridView1.Visible = false;
}
}
catch
{
GridView1.Visible = false;
}
tblPartialFooter.Visible = GridView1.Visible;
}
what am i doing wrong?
jessjing
Contributor
4392 Points
872 Posts
Re: Gridview cell value
Nov 06, 2006 07:42 AM|LINK
hi,
you said your GridView even not showing?
look at your code.
you add GridView1.Visible=false in the else and catch block.
may be your ds.Tables[0].Rows.Count < =0 ?????
check it
ArchangelOfD...
Member
30 Points
8 Posts
Re: Gridview cell value
Nov 06, 2006 08:26 AM|LINK
it's still not working. how should i know what rows.cells i should change when i don't even know the number of records the database has?
is there a way to loop through all the Rows. Cells and when there is a record that is less than zero, that's the time i set the forecolor to red?
enjaya
Member
20 Points
4 Posts
Re: Gridview cell value
Nov 06, 2006 04:03 PM|LINK
Hi You can change the gridview cell value only during rowdatabound event.
so attach rowdatabound event to gridview like this
ArchangelOfD...
Member
30 Points
8 Posts
Re: Gridview cell value
Nov 07, 2006 01:26 AM|LINK
myra013
Member
7 Points
12 Posts
Re: Gridview cell value
Dec 17, 2007 02:03 AM|LINK
yeah..problem solved..