This is a migrated thread and some comments may be shown as answers.

RadGrid TextBox Width

9 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 16 Aug 2012, 09:15 PM
I am building a radgrid programmatically in the code behind.  I have been unsuccessful in changing the text box width.  I have tried all sorts of different variations of header-style properties along with mastertable view settings.  I am new to the RadGrid controls and here is how I am currently adding my fields to the radgrid.
Dim boundColumn As GridBoundColumn
boundColumn = New GridBoundColumn()
gridPrgGrpDefinition.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "GrantName"
boundColumn.HeaderText = "Grant Name"
boundColumn.EditFormColumnIndex = 0
boundColumn.HeaderStyle.Width = Unit.Percentage(35)

Doug

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Aug 2012, 05:42 AM
Hi,

BoundColumn will be rendered as textbox in edit mode only. Try setting ItemStyle width as shown below.
VB:
boundColumn.ItemStyle.Width = Unit.Pixel(40)

Thanks,
Shinu.
0
Doug
Top achievements
Rank 1
answered on 17 Aug 2012, 03:10 PM
Thanks Shinu for your reply.  I have tried ItemStyle without any luck. Using the header style I can get the column headers to change, but I have not been able to get the Indvidual Text box widths to change.  Here is how I declared my grid and mastertable view.  I may am missing a setting or have something set incorrectly.

Dim gridPrgGrpDefinition As New RadGrid()
gridPrgGrpDefinition.ID = "gridPrgGrpDefinition"
PlaceHolder1.Controls.Add(gridPrgGrpDefinition)
Dim xmlnode As XmlNode = xmlPrgGrps.SelectSingleNode("//PrgGrpList[@GrantId ='" & HttpContext.Current.Session("PrgGrpId") & "']")
If Not IsNothing(xmlnode) Then
Dim xmlImportNode As XmlNode = xmlPrgGrpDefinition.ImportNode(xmlnode, True)
xmlRoote.AppendChild(xmlImportNode)
Dim streamreader As New StringReader(xmlPrgGrpDefinition.InnerXml)
Dim xmlreader As XmlTextReader = New XmlTextReader(streamreader)
Dim dataset As DataSet = New DataSet
dataset.ReadXml(xmlreader)
gridPrgGrpDefinition.DataSource = dataset
End If
gridPrgGrpDefinition.MasterTableView.DataKeyNames = New String() {"GrantId"}
gridPrgGrpDefinition.Width = Unit.Percentage(100)
gridPrgGrpDefinition.AllowPaging = True
gridPrgGrpDefinition.MasterTableView.AutoGenerateColumns = False
gridPrgGrpDefinition.MasterTableView.TableLayout = GridTableLayout.Fixed
gridPrgGrpDefinition.ClientSettings.Resizing.AllowColumnResize = True
gridPrgGrpDefinition.PageSize = 15
gridPrgGrpDefinition.MasterTableView.EditFormSettings.ColumnNumber = 7
gridPrgGrpDefinition.MasterTableView.EditFormSettings.CaptionFormatString = HttpContext.Current.Session("PrgGrpName") & " Definition"
gridPrgGrpDefinition.MasterTableView.Width = Unit.Percentage(100)
Dim boundColumn As GridBoundColumn
boundColumn = New GridBoundColumn()
gridPrgGrpDefinition.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "GrantName"
boundColumn.HeaderText = "Grant Name"
boundColumn.EditFormColumnIndex = 0
boundColumn.ItemStyle.Width = Unit.Percentage(35)

I have change my settings to the grid and mastertable view multiple times trying some different settings so I may have caused myself an issue.
Thanks,

Doug
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2012, 07:33 AM
Hi Doug,

I guess you want to change the width of the BoundColumn(in edit mode). Here is the code snippet I tried to change the width of the Boundcolumn in edit mode.

VB:
Private Sub grid_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
        Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim textbox As TextBox = DirectCast(item("GrantName").Controls(0), TextBox)
        textbox.Width = Unit.Percentage(35)
    End If
End Sub

Thanks,
Shinu.
0
Doug
Top achievements
Rank 1
answered on 28 Aug 2012, 05:12 PM
Thanks Shinu that worked to adjust the width of the text box in the column.  I now need to adjust the width of the column that contains the text box.  I can change the Header Width on the Grid above, but I can not adjust the width where the text box and the label exist.  Using the setup above can you see something that I can change to help with that.
Thanks,
Doug
0
Doug
Top achievements
Rank 1
answered on 29 Aug 2012, 03:45 PM
I did get this figured out by changing some of the width properties on the grid and removing the width property on the last column.  The columns now adjust to fit the text in the fields.  That will work for now.  Thanks for your help.
0
Doug
Top achievements
Rank 1
answered on 29 Aug 2012, 09:15 PM
I have now moved on to updating the radgrid that is built entirely in the code behind on the page init event. The grid is keeping the Header Values, but I am losing the all the edit mode text boxes after an update.  I would also like to update the header values with the new data entered by the user.  Since this grid is built entirely in the code behind I am not quite sure how I would rebind the data.  Any help would be appreciated.
Thanks,

Doug
0
Tsvetina
Telerik team
answered on 03 Sep 2012, 10:36 AM
Hello Doug,

As long as the grid is created correctly in code behind, there would not be any difference in the way you perform updates, compared to a statically declared grid.
Can you confirm that the order of creating and adding parts of the grid follows the sample posted here:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section22

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Doug
Top achievements
Rank 1
answered on 04 Sep 2012, 09:01 PM
Tsvetina,

Thanks for you reply.  I was able to figure out how to keep my edit mode fields after an update.  The issue I am having now is that once I complete an update I want to have the read only fields of the grid to be refreshed with the user updates.  They are keeping their original value.  The grid is being build in the Page Init method so if I try to update the datasource with the new field I get double the header columns that are keeping the older values.  I can attach the code if that will help.

Thanks again,
Doug
0
Doug
Top achievements
Rank 1
answered on 05 Sep 2012, 03:37 PM
I was able to figure out the refresh of the fields after an update.  I needed to remove any datasource or set it to null or nothing so the NeedDataSource event would fire.  The fields refreshed after that.
Tags
Grid
Asked by
Doug
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Doug
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or