[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Assign cssClass after data.Rows.Add(row)

Posted on 2004-09-23
7
Medium Priority
?
428 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 2000 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
Technology Partners: 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 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