Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan 7 3575
off the top of my head in your load event after binding its something like:
dgMarks.Columns (0).ItemStyle.H orizontalAlign= HorizontalAlign .Center
or declared it would probably be something like this
<ItemStyle Width="150px" VerticalAlign=" middle" HorizontalAlign ="right" />
You might have to pick it apart a bit, its not tested.
--
--
Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
Any formatting can be done through the style sections -
ItemStyle/HeaderStyle/FooterStyle, etc - with the actual records, you'd use
ItemStyle-HorizontalAlign ="right"
--
David Wier
MVP/ASPInsider http://aspnet101.com http://aspexpress.com
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
David, could you please show me an example of formatting using the
style sections?
Arpan
David Wier wrote:
Any formatting can be done through the style sections -
ItemStyle/HeaderStyle/FooterStyle, etc - with the actual records, you'd use
ItemStyle-HorizontalAlign ="right"
--
David Wier
MVP/ASPInsider http://aspnet101.com http://aspexpress.com
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
John, using
dgMarks.Columns (0).ItemStyle.H orizontalAlign = HorizontalAlign .Right
after binding the data to the DataGrid generates the following error:
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
pointing to the above line. Even the code
Response.Write( dgMarks.Columns .Count)
evaluates to 0! If the ItemStyle line is removed, then I can see the
DataGrid displaying the 4 columns - ID, UserID, Subject & Marks. So how
come the Columns count property evaluates to 0?
Thanks,
Regards,
Arpan
John Timney (MVP) wrote:
off the top of my head in your load event after binding its something like:
dgMarks.Columns (0).ItemStyle.H orizontalAlign= HorizontalAlign .Center
or declared it would probably be something like this
<ItemStyle Width="150px" VerticalAlign=" middle" HorizontalAlign ="right" />
You might have to pick it apart a bit, its not tested.
--
--
Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
Sorry Arpan,
I dont have a working environment in front of me. Here are a couple of
links that will help you get your example working by declaring the
<ItemStyle> http://msdn2.microsoft.com/en-us/lib...itemstyle.aspx http://msdn2.microsoft.com/en-us/lib...d.columns.aspx
Either way, you'll likely need to set the columns up for either approach to
work.
--
--
Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
John, using
dgMarks.Columns (0).ItemStyle.H orizontalAlign = HorizontalAlign .Right
after binding the data to the DataGrid generates the following error:
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
pointing to the above line. Even the code
Response.Write( dgMarks.Columns .Count)
evaluates to 0! If the ItemStyle line is removed, then I can see the
DataGrid displaying the 4 columns - ID, UserID, Subject & Marks. So how
come the Columns count property evaluates to 0?
Thanks,
Regards,
Arpan
John Timney (MVP) wrote:
>off the top of my head in your load event after binding its something like:
dgMarks.Column s(0).ItemStyle. HorizontalAlign =HorizontalAlig n.Center
or declared it would probably be something like this <ItemStyle Width="150px" VerticalAlign=" middle" HorizontalAlign ="right" />
You might have to pick it apart a bit, its not tested. -- -- Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message news:11******* **************@ i42g2000cwa.goo glegroups.com.. .
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
John, the problem in the code that I have shown in post #1 doesn't use
the <Columnscollect ion to populate the DataGrid i.e. the 4 columns
displayed in the DataGrid are generated automatically which why the
Columns count property evaluates to 0 but the examples shown in the 2
URLs you have referred use the <Columnscollect ion (like BoundColumn,
ButtonColumn, TemplateColumn) explicitly to render the DataGrid. They
don't show how to format records under auto-generated columns.
Arpan
John Timney (MVP) wrote:
Sorry Arpan,
I dont have a working environment in front of me. Here are a couple of
links that will help you get your example working by declaring the
<ItemStyle>
http://msdn2.microsoft.com/en-us/lib...itemstyle.aspx http://msdn2.microsoft.com/en-us/lib...d.columns.aspx
Either way, you'll likely need to set the columns up for either approach to
work.
--
--
Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
John, using
dgMarks.Columns (0).ItemStyle.H orizontalAlign = HorizontalAlign .Right
after binding the data to the DataGrid generates the following error:
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
pointing to the above line. Even the code
Response.Write( dgMarks.Columns .Count)
evaluates to 0! If the ItemStyle line is removed, then I can see the
DataGrid displaying the 4 columns - ID, UserID, Subject & Marks. So how
come the Columns count property evaluates to 0?
Thanks,
Regards,
Arpan
John Timney (MVP) wrote:
off the top of my head in your load event after binding its something
like:
dgMarks.Columns (0).ItemStyle.H orizontalAlign= HorizontalAlign .Center
or declared it would probably be something like this
<ItemStyle Width="150px" VerticalAlign=" middle" HorizontalAlign ="right"
/>
You might have to pick it apart a bit, its not tested.
--
--
Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Assume that a database table has the following 4 columns - ID, UserID,
Subject & Marks. I am retrieving the records existing in this DB table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the records
existing under the ID column to be right-aligned & the records existing
under the Marks column to be center-aligned. The records under UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
I suspect you will actually have to use the columns collection given your
trying to set an individual column as opposed to the whole grid.
--
Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@p 79g2000cwp.goog legroups.com...
John, the problem in the code that I have shown in post #1 doesn't use
the <Columnscollect ion to populate the DataGrid i.e. the 4 columns
displayed in the DataGrid are generated automatically which why the
Columns count property evaluates to 0 but the examples shown in the 2
URLs you have referred use the <Columnscollect ion (like BoundColumn,
ButtonColumn, TemplateColumn) explicitly to render the DataGrid. They
don't show how to format records under auto-generated columns.
Arpan
John Timney (MVP) wrote:
>Sorry Arpan,
I dont have a working environment in front of me. Here are a couple of links that will help you get your example working by declaring the <ItemStyle>
http://msdn2.microsoft.com/en-us/lib...itemstyle.aspx http://msdn2.microsoft.com/en-us/lib...d.columns.aspx
Either way, you'll likely need to set the columns up for either approach to work. -- -- Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message news:11******* **************@ m73g2000cwd.goo glegroups.com.. .
John, using
dgMarks.Columns (0).ItemStyle.H orizontalAlign = HorizontalAlign .Right
after binding the data to the DataGrid generates the following error:
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
pointing to the above line. Even the code
Response.Write( dgMarks.Columns .Count)
evaluates to 0! If the ItemStyle line is removed, then I can see the
DataGrid displaying the 4 columns - ID, UserID, Subject & Marks. So how
come the Columns count property evaluates to 0?
Thanks,
Regards,
Arpan
John Timney (MVP) wrote: off the top of my head in your load event after binding its something like:
dgMarks.Column s(0).ItemStyle. HorizontalAlign =HorizontalAlig n.Center
or declared it would probably be something like this <ItemStyle Width="150px" VerticalAlign=" middle" HorizontalAlig n="right" />
You might have to pick it apart a bit, its not tested. -- -- Regards
John Timney (MVP)
"Arpan" <ar******@hotma il.comwrote in message news:11******* **************@ i42g2000cwa.goo glegroups.com.. .
Assume that a database table has the following 4 columns - ID,
UserID,
Subject & Marks. I am retrieving the records existing in this DB
table
& displaying them in a DataGrid like this:
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection(" ........")
sqlDapter = New SqlDataAdapter( "SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill( dSet, "Marks")
dgMarks.DataSou rce = dSet
dgMarks.DataBin d()
End Sub
</script>
<form eunat="server">
<asp:DataGrid ID="dgMarks" HeaderStyle-Font-Bold="true"
HeaderStyle-HorizontalAlign ="center" runat="server"/>
</form>
The above will retrieve & display all the records existing in the 4
columns in the DataGrid. By default all the records in the different
cells in the DataGrid will be left-aligned. Now I want only the
records
existing under the ID column to be right-aligned & the records
existing
under the Marks column to be center-aligned. The records under
UserID &
Subject columns should remain left-aligned.
How do I accomplish this?
Thanks,
Arpan
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: PankajBanga |
last post by:
Is there anyway to align HeaderText different from text in the column. I want my text to be right aligned and headertext to be center. I don't want to add blank spaces in HeaderText as I am using a function which autoresizes the column.
thanks
|
by: Frnak McKenney |
last post by:
One of the reasons given for the Allied victory in WWI is that the
Nazi armament industry invested so much effort in creating new
weapons (e.g. the jet plane) it wasn't able to develop any of them
to the point of mass-production. There are days when I experience
the same difficulties with C# and dotNET: there are twelve ways to
do 'most _any_thing, and I wind up exploring six before I find an
acceptable solution. <grin>
Case in...
|
by: Sam |
last post by:
Hi guys,
I tried to use DataGridTextBoxColumn alignment property to format my data in
the datagrid and I don't quite get what I'd like it to be. The problem is
that when I set the alignment property to alignment right, the column header
text gets so close to the right edge of the column header and that makes it
difficult to read. Am I missing something?
Thanks
|
by: cr113 |
last post by:
How do I format text in datagrid column? I have a column of currency
values and I want them all to display with 2 decimal points (XXX.XX).
I figured out how to set the width and alignment as follows:
DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 140
DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 125
DataGrid1.TableStyles(0).GridColumnStyles(0).Alignment = 0
DataGrid1.TableStyles(0).GridColumnStyles(1).Alignment = 1
|
by: John Smith |
last post by:
Hi all;
Putting "Due" into the column header of a datagrid.
Font is a proportional fort.
When the alignment is left, there is some space between the column separator
bar and the D in Due. When the alignment is center, Due is centered in the
header box. When the alignment is right, the e in Due is partially covered
by the column separator bar. Adding space after Due (i.e.. "Due ") does
not work. HeaderText seems to be trimmed before...
| |
by: Simon Abolnar |
last post by:
Is it possible to align headers and text in different way.
Because with:
dgts.GridColumnStyles(0).Alignment = HorizontalAlignment.Center
alignment is set for all column (header and text).
Thanks for help!
Simon
|
by: Earl |
last post by:
Any known fixes for the wacky right-alignment bug in the WinForms datagrid
(VS2003)?
I've tried Ken's workaround
(http://www.windowsformsdatagridhelp.com/default.aspx?ID=4bfab32d-9cff-4f5c-ba95-49bb9074a8bc),
but I get no alignment at all when calling the class.
George Shephard's site, while imminently useful, does not have an anwer for
this issue.
|
by: Doug Bell |
last post by:
Hi
Does anyone know (or point me where I can find) how to set the alignment of
a DataGrid Column Header different to the alignment of the column.
I am trying to show some Right aligned columns and the header looks wrong
squashed to the right. If I could even add a trailing space but it trims any
trailing spaces off.
Thanks
|
by: rn5a |
last post by:
When the EditCommandColumn in a DataGrid is clicked, all the
BoundColumns get replaced by TextBoxes so that users can alter the
data. By default, the Text in the TextBoxes are left-aligned. Is there
any way by which the Text in some of the TextBoxes, not all, be
center-aligned or right-aligned?
Please note that I am referring to the alignment of the Text in the
TextBoxes & NOT the alignment of the TextBoxes within the cells in the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |