?
Solved

styling of asp:boundcolumn

Posted on 2007-10-16
8
Medium Priority
?
558 Views
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,

Brian
0
Comment
Question by:briancostea
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:S31B1
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'
0
 

Author Comment

by:briancostea
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,

Brian
0
 
LVL 4

Accepted Solution

by:
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">
<itemTempate>
<asp:Label ID="label1" runat="server" Text='<%Bind("value1")' CssClass='<%Eval("value2")'/>
</itemTempate>
<editTempate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%Bind("value1")' CssClass='<%Eval("value2")'/>
</editTempate>
</asp:TemplateField>
0
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

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

Author Comment

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

Assisted Solution

by:S31B1
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.
0
 

Author Comment

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

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

Author Comment

by:briancostea
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,

Brian
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

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