Solved

Assign cssClass after data.Rows.Add(row)

Posted on 2004-09-23
7
424 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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