styling of asp:boundcolumn

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
briancosteaAsked:
Who is Participating?
 
S31B1Commented:
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
 
S31B1Commented:
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
 
briancosteaAuthor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
briancosteaAuthor Commented:
thanks, I'll give it a try today and let you know.
0
 
briancosteaAuthor Commented:
I get the same error ... Inside VS 2005, I get the error:
"Code blocks are not supported in this context."
0
 
S31B1Commented:
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
 
briancosteaAuthor Commented:
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
 
briancosteaAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.