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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid Aligning columns 2

Status
Not open for further replies.

checkai

Programmer
Jan 17, 2003
1,629
0
0
US
I have a dg that is dynamically populated. It has 4 colums but I only want the right 3 columns to be right aligned. Possible? How?

Thanks

DLC
 
check: If you can somehow set the column's visible property to false that should do it. If I could see your code might have a better idea at how to approach this. There are probably other mechanisms one could use for this.
 
I wouldn't want anything left not visible..I want to see it all I just want it to look like a report where the left most column is left aligned and the other 3 columns are right aligned within their column.

dlc
 
One approach would be to use a css file and reference the alignment there (see thread855-618689).
 
Here's my code:

Sub bindGrid()
dgBU.DataSource = CreateDataSource("total")
dgBU.DataBind()
dgBU.Dispose()
End Sub

Function CreateDataSource(ByVal grid) As ICollection
Dim dv As DataView
Dim objConn As SqlConnection = New SqlConnection()
objConn.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")

Dim dt As DataTable
Dim dr As DataRow
Dim i As Integer
Dim strsql As String
Dim dsResults As New DataSet()

'create a DataTable
' If the command string is empty
dt = New DataTable()

strsql = "VKFORMS_SPCreditMGTARBusinessUnit '" & ddlSort.SelectedItem.Value & "'"
objConn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(strsql, objConn)
da.Fill(dsResults)
dt = dsResults.Tables(0)
dv = New DataView(dt)

da.Dispose()
objConn.Close()
'return a DataView to the DataTable
CreateDataSource = dv
End Function


It returns 4 fields

Business Unit - total - over 90 - over 120

I want business unit to be left aligned and the other 3 to be right aligned....also, is there a way to put a total row at the bottom...???
thanks,
dlc
 
Select the data grid
click property builder
click format
expand Columns from the objects windows
expand which column you want to format
select Item
format item

Jason Meckley
Database Analyst
WITF
 
Use the ItemStyle-HorizontalAlign="Right" property for those columns you wish to right align.

Dee
 
Dee,
How do I say which column that I want to align? I'm assuming this needs to be done after the dataBind() because of it being a dynamic population.

dlc
 
no, this is done on the aspx file, no the code behind file.

<asp:DataGrid>
<Columns>
<Bound Column DataField=&quot;?&quot; HeaderText=&quot;?&quot; [All other formatting properities] >
</Columns>
</asp:DataGrid>

This can be done in the actual html view, or through the properity builder in design view.

Jason Meckley
Database Analyst
WITF
 
Ok, I've now actually typed in my fields that my SP is returning...however, I need to change something because I'm returning 8 rows instead of the 4....so something in the code behind is doubling up this binding...

dlc
 
uncheck the field create columns automatically at runtime

Regards
Parchure Nikhil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top