472,143 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

ASP.NET DataGrid - how change edit textbox widths?

Hi all,

I have an ASP.NET DataGrid wherein there is an edit link for each row. Upon
clicking the link, certan fields in that row display in text boxes so that
they may be edited. I would like some textboxes to be wider, some narrower.
By default, they are all the same pre-defined width.

Does anyone know how I can do this?

Thanks very much,
Ron

Nov 15 '05 #1
3 9360
Hi Ronald,

I think that it depends of how you declare your grid, below you will find an
example of how I do it, you will see that I declare my controls in the way I
want.

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="550"
ItemStyle-HorizontalAlign="left" ItemStyle-CssClass="comunrow">
<itemtemplate>
<asp:Label Runat="server" Text='<%#
((CtpSentVia)Container.DataItem).Name%>' ID="Label23">
</asp:Label>
</itemtemplate>
<EditItemTemplate>
<asp:TextBox Width=100 CssClass="text" Runat="server" ID="SentViaName"
Text='<%# ((CtpSentVia)Container.DataItem).Name%>'></asp:TextBox>
<asp:CustomValidator id="Customvalidator2"
ControlToValidate="SentViaName"
OnServerValidate="ServerValidation"
ClientValidationFunction="IMValidator"
Display="Static"
ValidateIfBlank="yes"
ErrorMessage="*"
PopUPMessage="The Name can not be null"
runat="server"/>
</EditItemTemplate>
</asp:templatecolumn>

If you don;t use the TemplateColumn construction then you could set the
different parameters of the TextBox, the pseudocode below will give you an
idea:

protected void EditHandler( sender o, ... )
{
//get the selected row
int rowselected = grid.SelectedIndex;
TextBox textbox = (TextBox) grid[ rowselected].FindControl("TextBox
Name");
textbox.Width = 40;
}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ronald S. Cook" <rs****@westinis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi all,

I have an ASP.NET DataGrid wherein there is an edit link for each row. Upon clicking the link, certan fields in that row display in text boxes so that
they may be edited. I would like some textboxes to be wider, some narrower. By default, they are all the same pre-defined width.

Does anyone know how I can do this?

Thanks very much,
Ron

Nov 15 '05 #2
Thanks. If I use the template column instead, what to I change in my update
code? Currently, I reference the value in the edit textbox as:

string strFirstName = ((TextBox)e.Item.Cells[1].Controls[0]).Text

Now that it's a template column, how do I reference what the user has
entered (or may have changed)?

Thanks,
Ron

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:OF*************@TK2MSFTNGP10.phx.gbl...
Hi Ronald,

I think that it depends of how you declare your grid, below you will find an example of how I do it, you will see that I declare my controls in the way I want.

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="550"
ItemStyle-HorizontalAlign="left" ItemStyle-CssClass="comunrow">
<itemtemplate>
<asp:Label Runat="server" Text='<%#
((CtpSentVia)Container.DataItem).Name%>' ID="Label23">
</asp:Label>
</itemtemplate>
<EditItemTemplate>
<asp:TextBox Width=100 CssClass="text" Runat="server" ID="SentViaName"
Text='<%# ((CtpSentVia)Container.DataItem).Name%>'></asp:TextBox>
<asp:CustomValidator id="Customvalidator2"
ControlToValidate="SentViaName"
OnServerValidate="ServerValidation"
ClientValidationFunction="IMValidator"
Display="Static"
ValidateIfBlank="yes"
ErrorMessage="*"
PopUPMessage="The Name can not be null"
runat="server"/>
</EditItemTemplate>
</asp:templatecolumn>

If you don;t use the TemplateColumn construction then you could set the
different parameters of the TextBox, the pseudocode below will give you an
idea:

protected void EditHandler( sender o, ... )
{
//get the selected row
int rowselected = grid.SelectedIndex;
TextBox textbox = (TextBox) grid[ rowselected].FindControl("TextBox
Name");
textbox.Width = 40;
}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ronald S. Cook" <rs****@westinis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi all,

I have an ASP.NET DataGrid wherein there is an edit link for each row.

Upon
clicking the link, certan fields in that row display in text boxes so that they may be edited. I would like some textboxes to be wider, some

narrower.
By default, they are all the same pre-defined width.

Does anyone know how I can do this?

Thanks very much,
Ron


Nov 15 '05 #3
Hi,

Well you should not have to change anything, this is a line that I use in
the update handler:
item.Name = ((TextBox)e.Item.FindControl("SentViaName")).Text;
As you see I'm using almost the same construction than you , only that
instead of knowing the exact location of the control I use FindControl()

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ronald S. Cook" <rs****@westinis.com> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Thanks. If I use the template column instead, what to I change in my update code? Currently, I reference the value in the edit textbox as:

string strFirstName = ((TextBox)e.Item.Cells[1].Controls[0]).Text

Now that it's a template column, how do I reference what the user has
entered (or may have changed)?

Thanks,
Ron

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:OF*************@TK2MSFTNGP10.phx.gbl...
Hi Ronald,

I think that it depends of how you declare your grid, below you will find
an
example of how I do it, you will see that I declare my controls in the way
I
want.

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="550"
ItemStyle-HorizontalAlign="left" ItemStyle-CssClass="comunrow">
<itemtemplate>
<asp:Label Runat="server" Text='<%#
((CtpSentVia)Container.DataItem).Name%>' ID="Label23">
</asp:Label>
</itemtemplate>
<EditItemTemplate>
<asp:TextBox Width=100 CssClass="text" Runat="server" ID="SentViaName"
Text='<%# ((CtpSentVia)Container.DataItem).Name%>'></asp:TextBox>
<asp:CustomValidator id="Customvalidator2"
ControlToValidate="SentViaName"
OnServerValidate="ServerValidation"
ClientValidationFunction="IMValidator"
Display="Static"
ValidateIfBlank="yes"
ErrorMessage="*"
PopUPMessage="The Name can not be null"
runat="server"/>
</EditItemTemplate>
</asp:templatecolumn>

If you don;t use the TemplateColumn construction then you could set the
different parameters of the TextBox, the pseudocode below will give you

an idea:

protected void EditHandler( sender o, ... )
{
//get the selected row
int rowselected = grid.SelectedIndex;
TextBox textbox = (TextBox) grid[ rowselected].FindControl("TextBox
Name");
textbox.Width = 40;
}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ronald S. Cook" <rs****@westinis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi all,

I have an ASP.NET DataGrid wherein there is an edit link for each row.

Upon
clicking the link, certan fields in that row display in text boxes so

that they may be edited. I would like some textboxes to be wider, some

narrower.
By default, they are all the same pre-defined width.

Does anyone know how I can do this?

Thanks very much,
Ron



Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by louise raisbeck | last post: by
2 posts views Thread by CSL | last post: by
2 posts views Thread by TB | last post: by
2 posts views Thread by Rajani | last post: by
9 posts views Thread by rn5a | last post: by
2 posts views Thread by slinky | last post: by
reply views Thread by leo001 | last post: by

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.