How do you change the size of a DataGrid "edit" te

Dominic51

New Member
Hi,<BR><BR>Does anybody know how you change the size of the textbox you get in a Bound Column when you "Edit" a DataGrid? I would like the textboxes to be longer if the field to be edited is long, and vice versa.<BR><BR>Is there a way to do this, or are you stuck with a default size?<BR><BR>Thanks for your help!<BR><BR>JON<BR><BR>************************************************** *****************<BR> THE CODE<BR>************************************************** *****************<BR><BR><%@ Page Language="VB" Debug="true" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.Oledb" %><BR><BR><script language="VB" runat="server"><BR> Dim objConn as New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA<BR>Source=C:Documents and SettingsAdministratorMy DocumentsJon<BR>DocsMiscAccess emp.mdb" )<BR> Dim ds as Dataset = New DataSet()<BR> Dim objAdapter as New OleDbDataAdapter("SELECT * FROM tblItems", objConn)<BR><BR> Sub Page_Load(sender as object, e as eventargs)<BR> objConn.Open()<BR> objAdapter.Fill(ds, "tblItems")<BR> dg.DataSource = ds<BR> dg.DataMember = "tblItems"<BR><BR> If Not Page.IsPostBack Then<BR> dg.Databind()<BR> End If<BR> End Sub<BR><BR> sub dg_edit(sender as object, e as DataGridCommandEventArgs)<BR> dg.edititemindex = e.item.itemindex<BR> dg.databind()<BR> end sub<BR><BR><BR> sub dg_cancel(sender as object, e as DataGridCommandEventArgs)<BR> dg.edititemindex = -1<BR> dg.databind()<BR> end sub<BR><BR> sub dg_update(sender as object, e as DataGridCommandEventArgs)<BR> dim tbItemTitle as TextBox = e.Item.Cells(2).Controls(0)<BR> dim tbItemSummary as TextBox = e.Item.Cells(3).Controls(0)<BR><BR> Dim strSQL As String<BR> strSQL = "UPDATE tblItems SET ItemTitle = '" & tbItemTitle.Text & "',<BR>ItemSummary = '" & tbItemSummary.Text & "' WHERE ItemID = " &<BR>e.Item.Cells(0).Text<BR><BR> Dim objCommand as New OleDbCommand(strSQL, objConn)<BR> objCommand.ExecuteNonQuery()<BR><BR> ds.Tables.Clear<BR> objAdapter.Fill(ds, "tblItems")<BR><BR> dg.edititemindex = -1<BR> dg.DataBind()<BR> end sub<BR><BR></script><BR><BR><html><body><BR> <form runat="server"><BR> <asp:DataGrid id="dg" runat="server"<BR> Bordercolor="black"<BR> gridlines="vertical"<BR> font-names="Arial"<BR> font-size="10pt"<BR> cellpadding="4"<BR> cellspacing="0"<BR> width="100%"<BR> ShowFooter="True"<BR> HeaderStyle-BackColor="#cccc99"<BR> FooterStyle-BackColor="#cccc99"<BR> ItemStyle-BackColor="#ffffff"<BR> AlternatingItemStyle-Backcolor="#cccccc"<BR> AutoGenerateColumns="False"<BR> OnEditCommand="dg_edit"<BR> OnCancelCommand="dg_cancel"<BR> OnUpdateCommand="dg_update"><BR><BR> <Columns><BR> <asp:BoundColumn HeaderText="ItemID" DataField="ItemID" ReadOnly="true" /><BR> <asp:BoundColumn HeaderText="ItemType" DataField="ItemTypeID"<BR>ReadOnly="true" /><BR> <asp:BoundColumn HeaderText="ItemTitle" DataField="ItemTitle" /><BR> <asp:BoundColumn HeaderText="ItemSummary" DataField="ItemSummary" /><BR> <asp:editcommandcolumn edittext="Edit" CancelText="Cancel"<BR>UpdateText="Save" HeaderText="" /><BR> </Columns><BR> </asp:dataGrid><BR> </form><BR></body></html><BR>You can do it in ItemCreated<BR><BR>Although there are a lot of examples using the .Width property to set the size, that just sets the style which kind of bugs me. I usually use Attributes.Add("size", "20") instead.<BR><BR>regards,<BR><BR>Dave Kawliche<BR>http://AccessHelp.net<BR>http://1ClickDB.comHi David,<BR><BR>Thanks for your answer - and excuse my ignorance - but can you show me a few lines of VB.NET code that would implement your suggestion?<BR><BR>Thanks,<BR><BR>JONIf it were only a "few lines of code" I would be happy to share it here. Unfortunately working with dynamically generated DataGrids can be a real pain with a lot of issues not easily explained in a short messageboard exchange. To give you a sense of this, the 1 Click DB .NET WebForm adapter uses a few hundred lines of code "behind the scenes" to just do basically what I thought the DataGrid should do "out of the box" when autogenerating columns.<BR><BR>I am working on a series of articles for my own web site to share some the experiences and techniques I have picked up working with WebForms, especially the DataGrid. Hopefully the first one will be out later this week !!<BR><BR>regards,<BR><BR>Dave Kawliche<BR>http://AccessHelp.net<BR>http://1ClickDB.comHi Dave,<BR><BR>Would be interested in seeing those articles when they come out - where would I find them?<BR><BR>JONYou can watch this URL for the announcement :<BR><BR>http://AccessHelp.net/news.asp<BR><BR>regards,<BR><BR>Dave Kawliche<BR>http://AccessHelp.net<BR>http://1ClickDB.com
 
Back
Top