473,325 Members | 2,480 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,325 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 9434
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
1
by: TB | last post by:
Hi All: I have this datagrid where space is very tight, and therefore I have to make sure that everything fits within a fixed screen width regardless of whether I am in list mode or in edit...
0
by: Andrea Trevisan | last post by:
That's a revival of a known thing I suppose.I hope it's useful. My problem was: I want to have a DataGrid with two Template columns: first with TextBox,second with Button.I want to fire an event...
3
by: louise raisbeck | last post by:
Hi, I have been on this for hours and just cannot work it out. I have a datagrid. I set the edititem index to a row to edit, that works. However if i want to put a value into this textbox it wont...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
2
by: TB | last post by:
Hi All: I have this datagrid where space is very tight, and therefore I have to make sure that everything fits within a fixed screen width regardless of whether I am in list mode or in edit...
2
by: Rajani | last post by:
Hello, <asp:DataGrid ID="dg1" AllowPaging="True" AllowSorting="True" AlternatingItemStyle-BackColor="#ccccff" AlternatingItemStyle-Font-Name="arial" AlternatingItemStyle-ForeColor="#333366"...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: slinky | last post by:
I had a successfully deployed datagrid reading an XML file and showing the data: Private Function MakeDataView() as DataView Dim myDataSet As New DataSet()...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.