styling of asp:boundcolumn

Posted on 2007-10-16
Medium Priority
Last Modified: 2013-11-26
Is there a way to set the the CSS class of an asp:boundcolumn dynamically?  I would like to set the padding-left margin based on a value for a database.  I tried the following, but I get an error message.

<asp:BoundColumn DataField="ItemDescr" HeaderText="Activity" ItemStyle-Width=600 ItemStyle-CssClass="<%#DataBinder.Eval(Container.DataItem, "ItemPosition") %>"></asp:BoundColumn>

Parser Error Message: Literal content ('<asp:BoundColumn DataField="ItemDescr" HeaderText="Activity" ItemStyle-Width=600 ItemStyle-CssClass="') is not allowed within a 'System.Web.UI.WebControls.DataGridColumnCollection'.

I think I cannot use a TemaplateItem because the rows of the datagrid are editable.  Does anyone know if this is possible?  Thanks,

Question by:briancostea
  • 5
  • 3

Expert Comment

ID: 20086766
I'm not sure if ItemStyle-CssClass is a data bound property, if it is, before the above code will work you will need to replace the the "Double Quotes" arround your <%#DataBinder.Eval(Container.DataItem, "ItemPosition") %> with 'Single Quotes'

Author Comment

ID: 20086900
Thanks, I tried that but get the same error message.  ItemStyle-CssClass is a property of the boundcolumn.  Can I still edit the row if I use a TemplateItem?  Thanks,


Accepted Solution

S31B1 earned 375 total points
ID: 20091971
Ok, the error I get when I try to do as you have done is as expected BoundField does not have a DataBinding Event and cannot be used in this way. You now need to convert your bound Field to a template field this is quite straight forward.

you can convert through the Desgin view or just write the code, here is an example of a gridview editable template field.

<asp:TemplateField HeaderText="Header" SortExpression="value1">
<asp:Label ID="label1" runat="server" Text='<%Bind("value1")' CssClass='<%Eval("value2")'/>
<asp:TextBox ID="TextBox1" runat="server" Text='<%Bind("value1")' CssClass='<%Eval("value2")'/>
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  


Author Comment

ID: 20093265
thanks, I'll give it a try today and let you know.

Author Comment

ID: 20093494
I get the same error ... Inside VS 2005, I get the error:
"Code blocks are not supported in this context."

Assisted Solution

S31B1 earned 375 total points
ID: 20093553
The example I presented works with a Gridview.

Please post code (as complete as possible) so I can understand why you may be having this issue.

Author Comment

ID: 20093594
I had to do this:
<asp:TemplateColumn HeaderText="Header">
                    <%#DataBinder.Eval(Container.DataItem, "ItemDescr")%>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ItemDescr") %>'></asp:TextBox>

Right now, I am trying to figugre out how to change the update to work.  I'll keep you informed.

Author Comment

ID: 20094421
Okay ... I got it all working now.  Thanks for the help!  I was able to adapt your dataview code to my datagrid.  Thanks for all the help!

BTW - You seem to be pretty knowlegable with datagrids, do you know how to parse a grid in reverse?  Basically the bottom up.  Let me know if I should open a new question and include a link to it.  Thanks,


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

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

807 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