473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Text Alignment in DataGrid Edit TextBox

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
DataGrid.

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

<asp:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="TheLabel" runat="server"><%#
DataBinder.Eval(Container.DataItem, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TheTextBox" runat="server"
style="text-align:center" Text=<%# DataBinder.Eval(Container.DataItem,
"Data") %/>
</EditItemTemplate>
</asp:TemplateColumn>

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 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
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 EditItemTemplate. 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:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="TheLabel" runat="server"><%#
DataBinder.Eval(Container.DataItem, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TheTextBox" runat="server"
style="text-align:center" Text=<%# DataBinder.Eval(Container.DataItem,
"Data") %/>
</EditItemTemplate>
</asp:TemplateColumn>

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 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
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 EditItemTemplate. 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:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="TheLabel" runat="server"><%#
DataBinder.Eval(Container.DataItem, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TheTextBox" runat="server"
style="text-align:center" Text=<%# DataBinder.Eval(Container.DataItem,
"Data") %/>
</EditItemTemplate>
</asp:TemplateColumn>

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 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
DataGrid.
Nov 29 '06 #4
Rocky how do you say that the EditItemTemplate is designed specially
for TextBox? In fact, instead of having a TextBox within the
EditItemTemplate, I can even have a CheckBox within the
EditItemTemplate. So I couldn't follow what makes you say that the
EditItemTemplate 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 EditItemTemplate. 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:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="TheLabel" runat="server"><%#
DataBinder.Eval(Container.DataItem, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TheTextBox" runat="server"
style="text-align:center" Text=<%# DataBinder.Eval(Container.DataItem,
"Data") %/>
</EditItemTemplate>
</asp:TemplateColumn>
>
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 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
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:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="TheLabel" runat="server"><%#
DataBinder.Eval(Container.DataItem, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TheTextBox" runat="server"
style="text-align:center" Text=<%# DataBinder.Eval(Container.DataItem,
"Data") %/>
</EditItemTemplate>
</asp:TemplateColumn>

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 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
DataGrid.
Nov 29 '06 #6
>From what I've seen there are no performance hits using the
edititemtemplate 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
edititemtemplate 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
edititemtemplate 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 EditItemTemplate. 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:TemplateColumn HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="TheLabel" runat="server"><%#
DataBinder.Eval(Container.DataItem, "Data") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TheTextBox" runat="server"
style="text-align:center" Text=<%# DataBinder.Eval(Container.DataItem,
"Data") %/>
</EditItemTemplate>
</asp:TemplateColumn>

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 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
DataGrid.
Nov 30 '06 #7

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

Similar topics

2
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
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
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...
2
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....
3
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). ...
7
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...
7
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...
0
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...
8
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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...
0
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...

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.