473,763 Members | 8,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9470
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:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="550"
ItemStyle-HorizontalAlign ="left" ItemStyle-CssClass="comun row">
<itemtemplate >
<asp:Label Runat="server" Text='<%#
((CtpSentVia)Co ntainer.DataIte m).Name%>' ID="Label23">
</asp:Label>
</itemtemplate>
<EditItemTempla te>
<asp:TextBox Width=100 CssClass="text" Runat="server" ID="SentViaName "
Text='<%# ((CtpSentVia)Co ntainer.DataIte m).Name%>'></asp:TextBox>
<asp:CustomVali dator id="Customvalid ator2"
ControlToValida te="SentViaName "
OnServerValidat e="ServerValida tion"
ClientValidatio nFunction="IMVa lidator"
Display="Static "
ValidateIfBlank ="yes"
ErrorMessage="* "
PopUPMessage="T he Name can not be null"
runat="server"/>
</EditItemTemplat e>
</asp:templatecol umn>

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.SelectedIn dex;
TextBox textbox = (TextBox) grid[ rowselected].FindControl("T extBox
Name");
textbox.Width = 40;
}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ronald S. Cook" <rs****@westini s.com> wrote in message
news:%2******** ********@tk2msf tngp13.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.Ite m.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.mach in AT dot.state.fl.us > wrote
in message news:OF******** *****@TK2MSFTNG P10.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:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="550"
ItemStyle-HorizontalAlign ="left" ItemStyle-CssClass="comun row">
<itemtemplate >
<asp:Label Runat="server" Text='<%#
((CtpSentVia)Co ntainer.DataIte m).Name%>' ID="Label23">
</asp:Label>
</itemtemplate>
<EditItemTempla te>
<asp:TextBox Width=100 CssClass="text" Runat="server" ID="SentViaName "
Text='<%# ((CtpSentVia)Co ntainer.DataIte m).Name%>'></asp:TextBox>
<asp:CustomVali dator id="Customvalid ator2"
ControlToValida te="SentViaName "
OnServerValidat e="ServerValida tion"
ClientValidatio nFunction="IMVa lidator"
Display="Static "
ValidateIfBlank ="yes"
ErrorMessage="* "
PopUPMessage="T he Name can not be null"
runat="server"/>
</EditItemTemplat e>
</asp:templatecol umn>

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.SelectedIn dex;
TextBox textbox = (TextBox) grid[ rowselected].FindControl("T extBox
Name");
textbox.Width = 40;
}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ronald S. Cook" <rs****@westini s.com> wrote in message
news:%2******** ********@tk2msf tngp13.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.Ite m.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****@westini s.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.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.Ite m.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.mach in AT dot.state.fl.us > wrote in message news:OF******** *****@TK2MSFTNG P10.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:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="550"
ItemStyle-HorizontalAlign ="left" ItemStyle-CssClass="comun row">
<itemtemplate >
<asp:Label Runat="server" Text='<%#
((CtpSentVia)Co ntainer.DataIte m).Name%>' ID="Label23">
</asp:Label>
</itemtemplate>
<EditItemTempla te>
<asp:TextBox Width=100 CssClass="text" Runat="server" ID="SentViaName "
Text='<%# ((CtpSentVia)Co ntainer.DataIte m).Name%>'></asp:TextBox>
<asp:CustomVali dator id="Customvalid ator2"
ControlToValida te="SentViaName "
OnServerValidat e="ServerValida tion"
ClientValidatio nFunction="IMVa lidator"
Display="Static "
ValidateIfBlank ="yes"
ErrorMessage="* "
PopUPMessage="T he Name can not be null"
runat="server"/>
</EditItemTemplat e>
</asp:templatecol umn>

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.SelectedIn dex;
TextBox textbox = (TextBox) grid[ rowselected].FindControl("T extBox
Name");
textbox.Width = 40;
}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ronald S. Cook" <rs****@westini s.com> wrote in message
news:%2******** ********@tk2msf tngp13.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
2340
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" ItemStyle-HorizontalAlign="center" ItemStyle-VerticalAlign="top"> <ItemTemplate><%# CType(Container.DataItem("DateStatut"),DateTime).ToString("yyyy-MM-dd") %></ItemTemplate> <EditItemTemplate> <asp:TextBox width="80" CssClass="edit_item" id="txtDateStatut"
1
2345
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 mode. But I have discovered that it is not enough to simply specify the column widths by way of 'HeaderStyle-Width="25px" ItemStyle-Width="25px"'-type properties inside in the <asp:BoundColumn> tags, because by default all the text boxes in edit mode...
0
2807
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 from button and I want to have a reference to TextBox to make use of it.The most difficult was the reference to TextBox. This sample is taken from MCAD/MCSD Exam 70-305/70-315 of Microsoft Press.This book is much more exhaustive than the brief...
3
1405
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 let me. I just cant find the control in the controlcollection for the cell. Is it because it hasnt rendered yet? (very annoying as i have set the edititem to the index, done my databound etc.) why doesnt it recognise the textbox? so: ...
2
6413
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
2057
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 mode. But I have discovered that it is not enough to simply specify the column widths by way of 'HeaderStyle-Width="25px" ItemStyle-Width="25px"'-type properties inside in the <asp:BoundColumn> tags, because by default all the text boxes in edit...
2
3248
by: Rajani | last post by:
Hello, <asp:DataGrid ID="dg1" AllowPaging="True" AllowSorting="True" AlternatingItemStyle-BackColor="#ccccff" AlternatingItemStyle-Font-Name="arial" AlternatingItemStyle-ForeColor="#333366" CellPadding="3" DataKeyField="empid" OnPageIndexChanged="chgpage" OnSortCommand="sortdg" PageSize="10" PagerStyle-Mode="NumericPages" Runat="server" PagerStyle-HorizontalAlign="Center" OnSelectedIndexChanged="chgsel"...
9
2727
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
2
1324
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() myDataSet.ReadXml(Server.MapPath("TimberSales.xml")) Dim view As DataView = New DataView(myDataSet.Tables(0)) view.AllowDelete = False view.AllowEdit = True view.AllowNew = False
0
10002
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
9938
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
9823
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
8822
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...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2794
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.