Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting DataGrid using VB code

Status
Not open for further replies.

2xhelix

IS-IT--Management
Jul 15, 2004
9
CA
I am trying, but getting no where.

I have a DataGrid object, that will be passed back to the .aspx page. But I want to set all the formating in code.

Can someone show me an example on how to apply a headerstyle, footer style, ect ect ...

Also, how would I ad a boundedColumns to the data grid?
thanks
 
Could you explain a little more of what you are trying to do? Do you want a grid to appear after doing something?

Hope everyone is having a great day!

Thanks - Jennifer
 
you can lookup members of boundcolumns and headers at - search for Datagrid members, and click the .net framework link. The key i would say in the boundcolumn is ItemStyle-(Whatever)... i have set the cssClass and class to a css file elsewhere for some font settings.
Code:
<asp:datagrid id="MasterGrid" runat="server" AutoGenerateColumns="false" width="98%" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" OnPageIndexChanged="MasterGrid_Page" PageSize="6" AllowPaging="true" OnSelectedIndexChanged="MasterGrid_Select" DataKeyField="Inc #" class=dg>
                <HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C" />
                <SelectedItemStyle forecolor="White" backcolor="#9471DE" />
                <PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages" />
                <ItemStyle backcolor="#DEDFDE" />
                <Columns>
                    <asp:buttoncolumn DataTextField="Inc #" commandname="Select" ItemStyle-Width=40 ItemStyle-HorizontalAlign="Center" HeaderText="Inc #" />
                    <asp:HyperLinkColumn Text="Edit" DataNavigateUrlField="Inc #" DataNavigateUrlFormatString="incDetails.aspx?Incident={0}" Target="_blank" />
                    <asp:HyperLinkColumn DataTextField="ClientName" ItemStyle-Wrap="False" HeaderText="Requestor" ItemStyle-VerticalAlign="Middle" DataNavigateUrlField="ClientID" ItemStyle-ForeColor="#FFFFFF" DataNavigateUrlFormatString="userDetails.aspx?clientid={0}" Target="_blank" />
	           		<asp:BoundColumn DataField="IncDate" HeaderText="Date" DataFormatString="{0:d}" ItemStyle-VerticalAlign="Middle" />
	           		<asp:BoundColumn DataField="IncPriority" HeaderText="Priority" ItemStyle-VerticalAlign="Middle" ReadOnly="True" />
	           		<asp:BoundColumn DataField="Description" HeaderText="Description" />	
	           		<asp:BoundColumn DataField="StaffName" HeaderText="Assigned" ItemStyle-Wrap="False" ItemStyle-VerticalAlign="Middle" />
	           		<asp:BoundColumn DataField="ClientEmail" HeaderText="Email" visible="false" />
	           		<asp:BoundColumn DataField="Status" HeaderText="Status" visible="false" />	           		
                </Columns>
        </asp:datagrid>
 
I was actually attempting to do this in VB code .. but I found out how to do it.
Code:
 MyDataGrid.HeaderStyle.BackColor = Color.FromArgb(204, 204, 255)
            MyDataGrid.BackColor = Color.White
            MyDataGrid.BorderColor = Color.Black
            MyDataGrid.CellPadding = 3
            MyDataGrid.Font.Size = UI.WebControls.FontUnit.Parse("8pt")
            MyDataGrid.Font.Name = "Verdana"
            MyDataGrid.AllowSorting = True
            MyDataGrid.AutoGenerateColumns = False

Just have one small problem if any of you guys know how to do this.

The OnSortCommand .. how would I specify the function call in the vb code .. and not inside the <ASP:DATAGRID tag?

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top