Solved

Assign cssClass after data.Rows.Add(row)

Posted on 2004-09-23
7
416 Views
Last Modified: 2012-08-13
How do you assign the property of a column of a row when you add the row?
Here is the code that works but displays this row a different size and font:

DataTable data = dbAccess.getDataTable(con, table, sqlSv);
DataRow rowx;
rowx = data.NewRow();
dContent = Convert.ToDecimal(PriceTot);
sContent = dContent.ToString("###,###,###,###.#0");
rowx["Sub Total"]=sContent.ToString();
data.Rows.Add(rowx);
dg.DataSource = data;

However, cssClass is not a property of data, data.Rows, data.Columns, etc.
Then I assign the other rows the cssClass:

protected void OnItemDataBoundEventHandler(Object sender, DataGridItemEventArgs e)
{
     int iCtr = e.Item.Controls.Count;
     for (int i=0; i<iCtr; i++)
     {
      TableCell tcn = (TableCell) e.Item.Controls[i];
                tcn.CssClass = "clsListRecordHeader";
     }
}

BUT THIS DOESN'T PICK UP THE ADDED ROW -

Please HELP!
0
Comment
Question by:dcass
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:w_shaila
ID: 12138113
Where is your dg.DataBind() Statement? . Please check where you have written this Statement ?
This statemnet should be after adding the row to the DataTable.
I worked on one example. It is working fine . If you want I can send that Example
0
 

Author Comment

by:dcass
ID: 12138288
It's there - I just didn't copy it in.
The problem is that the OnItemDataBoundEventHandler event doesn't seem to get that row I added.
Yes, any examples are appreciated.
0
 
LVL 3

Accepted Solution

by:
w_shaila earned 500 total points
ID: 12138778
For Simplicity I am reading the data from XML to simulate your problem

ds.ReadXml(Server.MapPath("XMLFile1.xml"));

DataRow dr = ds.Tables[0].NewRow();
                  dr[0] = "10";
                  ds.Tables[0].Rows.Add(dr);
                  DataGrid1.DataSource = ds.Tables[0];
                  DataGrid1.DataBind();


The following code is in ItemDataBound
int iCtr = e.Item.Controls.Count;
                  for (int i=0; i<iCtr; i++)
                  {
                        TableCell tcn = (TableCell) e.Item.Controls[i];
                        tcn.CssClass = "menuskin";
                  }

menuskin is defined in aspx page as a style

.menuskin { FONT-WEIGHT: bold }

With this for the value "10" which is new also getting bold .

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:dcass
ID: 12142176
I don't see any difference between your code and mine.
Can you see anything different that you are doing to pick up the added row?
It still doesn't work on mine.
0
 

Author Comment

by:dcass
ID: 12142823
I figured it out - will give you the points for responding.
0
 
LVL 3

Expert Comment

by:w_shaila
ID: 12143739
Let me know what is the problem you had and How did you fix it?
0
 

Author Comment

by:dcass
ID: 12147974
There was nothing in the first column because it was just a "totals" column and it was trying to assign a hyperlink - I should have put all the code.
The code above actually worked, I just had more in there than I copied in.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now