Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Text Alignment in DataGrid Edit TextBox

Reply
Thread Tools

Text Alignment in DataGrid Edit TextBox

 
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      11-28-2006
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.

 
Reply With Quote
 
 
 
 
Gozirra
Guest
Posts: n/a
 
      11-29-2006
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
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      11-29-2006
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
> (E-Mail Removed) 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.


 
Reply With Quote
 
Rocky
Guest
Posts: n/a
 
      11-29-2006
Hi,
I'll suggest Edit Template mode because this is designed specially for
Text box.

Anshu
(E-Mail Removed) 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
> > (E-Mail Removed) 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.


 
Reply With Quote
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      11-29-2006
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
> (E-Mail Removed) 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
> > > (E-Mail Removed) 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.


 
Reply With Quote
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      11-29-2006
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
> (E-Mail Removed) 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.


 
Reply With Quote
 
Gozirra
Guest
Posts: n/a
 
      11-30-2006
>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.

(E-Mail Removed) 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
> > (E-Mail Removed) 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
Edit All Function for DataGrid, and Moving the Edit Function in a DataGrid Schultz ASP .Net 3 02-14-2005 04:47 AM
Set the width of the edit textbox after clicking on Edit link in datagrid... Sharon McCarty ASP .Net Datagrid Control 0 11-24-2004 06:41 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments