473,763 Members | 6,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text Alignment in DataGrid Edit TextBox

When the EditCommandColu mn 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
DataGrid.

Nov 28 '06 #1
6 3371
Yes there is. Use a template column instead. Heres a short little
example.

<asp:TemplateCo lumn HeaderText="Use rName">
<ItemTemplate >
<asp:Label ID="TheLabel" runat="server"> <%#
DataBinder.Eval (Container.Data Item, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox id="TheTextBox " runat="server"
style="text-align:center" Text=<%# DataBinder.Eval (Container.Data Item,
"Data") %/>
</EditItemTemplat e>
</asp:TemplateCol umn>

The style can be set to left, right or center. Of course you can also
set the cssclass as well. This is probably a better option but it all
works the same.

You can set the itemstyle-cssclass on a bound column but this only
applies to the display of the data within a label. When you switch to
edit, the style class is not applied to the textbox.
http://localhost/TestService1/WebForm2.aspx
rn**@rediffmail .com wrote:
When the EditCommandColu mn 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
DataGrid.
Nov 29 '06 #2
Again it's my dear Gozirra & as expected, you have once again provided
the solution I was looking out for.

Gozirra, a DataGrid can be set in the editable mode using BoundColumns
as well as EditItemTemplat e. Which one would you suggest & why? Are
there any performance issues involved using one over the other?
Gozirra wrote:
Yes there is. Use a template column instead. Heres a short little
example.

<asp:TemplateCo lumn HeaderText="Use rName">
<ItemTemplate >
<asp:Label ID="TheLabel" runat="server"> <%#
DataBinder.Eval (Container.Data Item, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox id="TheTextBox " runat="server"
style="text-align:center" Text=<%# DataBinder.Eval (Container.Data Item,
"Data") %/>
</EditItemTemplat e>
</asp:TemplateCol umn>

The style can be set to left, right or center. Of course you can also
set the cssclass as well. This is probably a better option but it all
works the same.

You can set the itemstyle-cssclass on a bound column but this only
applies to the display of the data within a label. When you switch to
edit, the style class is not applied to the textbox.
http://localhost/TestService1/WebForm2.aspx
rn**@rediffmail .com wrote:
When the EditCommandColu mn 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
DataGrid.
Nov 29 '06 #3
Hi,
I'll suggest Edit Template mode because this is designed specially for
Text box.

Anshu
rn**@rediffmail .com wrote:
Again it's my dear Gozirra & as expected, you have once again provided
the solution I was looking out for.

Gozirra, a DataGrid can be set in the editable mode using BoundColumns
as well as EditItemTemplat e. Which one would you suggest & why? Are
there any performance issues involved using one over the other?
Gozirra wrote:
Yes there is. Use a template column instead. Heres a short little
example.

<asp:TemplateCo lumn HeaderText="Use rName">
<ItemTemplate >
<asp:Label ID="TheLabel" runat="server"> <%#
DataBinder.Eval (Container.Data Item, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox id="TheTextBox " runat="server"
style="text-align:center" Text=<%# DataBinder.Eval (Container.Data Item,
"Data") %/>
</EditItemTemplat e>
</asp:TemplateCol umn>

The style can be set to left, right or center. Of course you can also
set the cssclass as well. This is probably a better option but it all
works the same.

You can set the itemstyle-cssclass on a bound column but this only
applies to the display of the data within a label. When you switch to
edit, the style class is not applied to the textbox.
http://localhost/TestService1/WebForm2.aspx
rn**@rediffmail .com wrote:
When the EditCommandColu mn 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
DataGrid.
Nov 29 '06 #4
Rocky how do you say that the EditItemTemplat e is designed specially
for TextBox? In fact, instead of having a TextBox within the
EditItemTemplat e, I can even have a CheckBox within the
EditItemTemplat e. So I couldn't follow what makes you say that the
EditItemTemplat e is designed specially for TextBox.

In fact, on the other hand, BoundColumns will always get replaced by
TextBoxes when the DataGrid is in the editable mode. So I believe, on
the contrary, BoundColumn is specially designed for TextBox, isn't it?

Correct me if I am wrong.
Rocky wrote:
Hi,
I'll suggest Edit Template mode because this is designed specially for
Text box.

Anshu
rn**@rediffmail .com wrote:
Again it's my dear Gozirra & as expected, you have once again provided
the solution I was looking out for.

Gozirra, a DataGrid can be set in the editable mode using BoundColumns
as well as EditItemTemplat e. Which one would you suggest & why? Are
there any performance issues involved using one over the other?
Gozirra wrote:
Yes there is. Use a template column instead. Heres a short little
example.
>
<asp:TemplateCo lumn HeaderText="Use rName">
<ItemTemplate >
<asp:Label ID="TheLabel" runat="server"> <%#
DataBinder.Eval (Container.Data Item, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox id="TheTextBox " runat="server"
style="text-align:center" Text=<%# DataBinder.Eval (Container.Data Item,
"Data") %/>
</EditItemTemplat e>
</asp:TemplateCol umn>
>
The style can be set to left, right or center. Of course you can also
set the cssclass as well. This is probably a better option but it all
works the same.
>
You can set the itemstyle-cssclass on a bound column but this only
applies to the display of the data within a label. When you switch to
edit, the style class is not applied to the textbox.
>
>
http://localhost/TestService1/WebForm2.aspx
rn**@rediffmail .com wrote:
When the EditCommandColu mn 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
DataGrid.
Nov 29 '06 #5
Gozirra, one thing I forgot to mention - the Text in the TextBoxes in
the BoundColumns when the DataGrid is in the editable mode can also be
center or right-aligned using this style

<style>
input{
text-align:center;
}
</style>

But the drawback of this is that all the TextBoxes in the page (be it
inside or outside the DataGrid) will have their Text aligned at the
center.
Gozirra wrote:
Yes there is. Use a template column instead. Heres a short little
example.

<asp:TemplateCo lumn HeaderText="Use rName">
<ItemTemplate >
<asp:Label ID="TheLabel" runat="server"> <%#
DataBinder.Eval (Container.Data Item, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox id="TheTextBox " runat="server"
style="text-align:center" Text=<%# DataBinder.Eval (Container.Data Item,
"Data") %/>
</EditItemTemplat e>
</asp:TemplateCol umn>

The style can be set to left, right or center. Of course you can also
set the cssclass as well. This is probably a better option but it all
works the same.

You can set the itemstyle-cssclass on a bound column but this only
applies to the display of the data within a label. When you switch to
edit, the style class is not applied to the textbox.
http://localhost/TestService1/WebForm2.aspx
rn**@rediffmail .com wrote:
When the EditCommandColu mn 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
DataGrid.
Nov 29 '06 #6
>From what I've seen there are no performance hits using the
edititemtemplat e or the bound column. I usually use boundcolumns when
I have no need for anything out of the ordinary. If all you require is
simple text input, then the bound column fills the need. I use
edititemtemplat e for cases where you need greater control over the
output. As you pointed out, you get greater flexibility with the
ability to use a number of different controls within the
edititemtemplat e and greater control over the styles applied to those
controls. So thats my 2 cents for what its worth.

rn**@rediffmail .com wrote:
Again it's my dear Gozirra & as expected, you have once again provided
the solution I was looking out for.

Gozirra, a DataGrid can be set in the editable mode using BoundColumns
as well as EditItemTemplat e. Which one would you suggest & why? Are
there any performance issues involved using one over the other?
Gozirra wrote:
Yes there is. Use a template column instead. Heres a short little
example.

<asp:TemplateCo lumn HeaderText="Use rName">
<ItemTemplate >
<asp:Label ID="TheLabel" runat="server"> <%#
DataBinder.Eval (Container.Data Item, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox id="TheTextBox " runat="server"
style="text-align:center" Text=<%# DataBinder.Eval (Container.Data Item,
"Data") %/>
</EditItemTemplat e>
</asp:TemplateCol umn>

The style can be set to left, right or center. Of course you can also
set the cssclass as well. This is probably a better option but it all
works the same.

You can set the itemstyle-cssclass on a bound column but this only
applies to the display of the data within a label. When you switch to
edit, the style class is not applied to the textbox.
http://localhost/TestService1/WebForm2.aspx
rn**@rediffmail .com wrote:
When the EditCommandColu mn 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
DataGrid.
Nov 30 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1106
by: Ing. Rajesh Kumar | last post by:
Hi everybody Is it possible to set the size of text boxes when in edit mode ? Thanks in advance Raja
6
6524
by: Aaron Smith | last post by:
Is there a way to put a limit on the text size of a datagrid column? Thanks, Aaron -- --- Aaron Smith Remove -1- to E-Mail me. Spam Sucks.
2
2339
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling functions very easy and nice. Anyway, I'm afraid that I haven't understood the data binding things correct. I'm using MySQL Connector/.NET to access my database from the
2
8093
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...
3
4196
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
7
2040
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.
7
1974
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
0
1002
by: Rod | last post by:
I want to be able to access the text in an edit text box which appears when editting a row in a datagrid Now I know that if you have a button column then you can do it like this. Sub UpdateGridData(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs) Dim objTextBox As TextBox
8
1983
by: =?Utf-8?B?bWlrZWc=?= | last post by:
Hi, I am building a small Help Desk application for my company and need to be able to edit "open" help desk issues. I use a simple datagrid to display each issue (6 per page) , with an Edit button. There are a lot of fields across, and my Network Admins would like a way of editing/updating each issue seperately in a a vertical form. I need a way of clicking on the edit button ,bringing up a form with the record, editng the fields, and...
0
10144
Oralloy
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...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
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...
1
7366
isladogs
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...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.