Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 grid view column back color...

Author  Topic 

jhermiz

3564 Posts

Posted - 2007-08-08 : 13:14:03
Jeff or any asp.net person out there...

Can I do something like so:


<asp:TemplateField HeaderText="Color">
<ItemTemplate>
<asp:Label id="lblColor" runat="server" BackColor='<%# DataBinder.Eval(Container, "DataItem.HTMLColor") %>'>
</asp:Label>
</ItemTemplate>
<ItemStyle Width="7%" />
<HeaderStyle ForeColor="White" />
</asp:TemplateField>


Look specifically at this line: <asp:Label id="lblColor" runat="server" BackColor='<%# DataBinder.Eval(Container, "DataItem.HTMLColor") %>'>

I am trying to set the background color of a column in the HTML itself, I cannot do it in the RowCreated event because the HTMLColor is stored as a String value in the db of hex representation. For instance, if I had #FFFFFF stored in the database table column HTMLColor and I pulled that in using that code.

Thanks,
Jon


Programmers HowTo's -- [url]http://jhermiz.googlepages.com[/url]

jhermiz

3564 Posts

Posted - 2007-08-08 : 14:13:50
Thought I had it with this:


Protected Sub gvKey_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvKey.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lbl As Label = CType(e.Row.FindControl("lblColor"), Label)
lbl.BackColor = System.Drawing.ColorTranslator.FromHtml(CType(DataBinder.Eval(e.Row.DataItem, "HTMLColor"), String))
lbl.ForeColor = lbl.BackColor
lbl.BorderColor = System.Drawing.ColorTranslator.FromHtml("#24618e")
lbl.BorderStyle = BorderStyle.Solid
lbl.BorderWidth = 1
End If
End Sub


However, any post backs and I lose all the formatting :(...
Least I got it on the code view though so far..now to figure out why the formatting is lost.

:(

Thanks

Programmers HowTo's -- [url]http://jhermiz.googlepages.com[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2007-08-08 : 14:18:23
Hmm change it to rowdatabound and it worked

Programmers HowTo's -- [url]http://jhermiz.googlepages.com[/url]
Go to Top of Page
   

- Advertisement -