Solved

Assign cssClass after data.Rows.Add(row)

Posted on 2004-09-23
7
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

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!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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