Datagrid question

E

EMW

I have a datagrid on my ASPx page bound to a dataview of a dataset table.
The first 4 columns are bound, the rest (31) are template columns with a
imagebutton inside.

I would like to be able to programmaticly change the colors (back- and fore)
of the header cells of these template columns.

How can I do this, if it is at all possible?

rg,
Eric
 
G

Guest

H

I haver done something similar to this. In my case i use to change the image in the header when it was clicked. On what criteria you want the color to be changed

----- EMW wrote: ----

I have a datagrid on my ASPx page bound to a dataview of a dataset table
The first 4 columns are bound, the rest (31) are template columns with
imagebutton inside

I would like to be able to programmaticly change the colors (back- and fore
of the header cells of these template columns

How can I do this, if it is at all possible

rg
Eri
 
R

Raheel Hussain

you can also do this with the help of java script.

i did that by using the following way to change the background color of
the datagrid row.

i added a javascript on the item createevent of grid

however i m using the following code to change the background color, you
can also try to change the fore color by changing the css class of TD
etc.

hope that helps

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
code
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim cn As New OleDb.OleDbConnection(connectionstring)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

Private Sub BindGrid()
'code to bind grid
End Sub



Private Sub dgusers_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgusers.ItemCreated
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.SelectedItem Then
e.Item.Attributes.Add("onMouseOver",
"this.style.backgroundColor='#0099cc';this.style.cursor='hand';")
e.Item.Attributes.Add("onMouseOut",
"this.style.backgroundColor='#f5f5f5';")
e.Item.Attributes.Add("onclick", "javascript:__doPostBack('"
& "dgusers:" & "ctrl" & e.Item.ItemIndex & ":ctrl0','')")
End If
End Sub



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
HTML
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

<asp:datagrid id="dgusers" runat="server" Width="100%"
HorizontalAlign="Center" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4"
PageSize="2" AllowPaging="True"
AllowSorting="True">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
CssClass="tborder" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns><asp:ButtonColumn Visible="False" Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
<PagerStyle BorderWidth="2px" BorderStyle="Ridge"
HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC" CssClass="tborder" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top