Solved

Assign cssClass after data.Rows.Add(row)

Posted on 2004-09-23
7
423 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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