By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

PreRender Error setting textbox width

P: 2
I have a PreRender event to set the width of my textbox when the Edit button is pressed on my grid here is the code:

Private Sub grdPBC_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPBC.PreRender
If grdPBC.EditItemIndex > -1 Then
Dim tbx As TextBox
tbx = CType(grdPBC.Items(grdPBC.EditItemIndex).Cells(4). Controls(0), TextBox)

tbx.Width = Unit.Pixel(50)
tbx = CType(grdPBC.Items(grdPBC.EditItemIndex).Cells(5). Controls(0), TextBox)
tbx.Width = Unit.Pixel(50)

End If
End Sub
So I bind the data to the grid and when you click on the edit button the width of the two textboxes are 50px. Perfect
But now after I bind the data to the grid I need to add data to one of the colomns, so I use a For Loop to go through the grid and add the data manually
Here is that code:
Dim dgItem As DataGridItem
Dim icount As Integer
Dim dGrandTotal As Double

For Each dgItem In grdPBC.Items

Dim cls As New ClassLibrary1.usp_GetPBCTotalForMonth
cls.Execute(ConfigurationSettings.AppSettings("Con nectionString"), grdPBC.Items(icount).Cells(0).Text, ddMonth.SelectedValue, ddYear.SelectedValue, txtFirstFriday.Text, dGrandTotal)

grdPBC.Items(icount).Cells(4).Text = Format(dGrandTotal, "$##,##0.00")

icount = icount + 1

Again that works fine. But if I now click on the Edit button the PreRender call throws an error on the line:
tbx = CType(grdPBC.Items(grdPBC.EditItemIndex).Cells(4). Controls(0), TextBox)
The error is:
"Run-time exception thrown : System.ArgumentOutOfRangeException - Specified argument was out of the range of valid values. Parameter name: index"

The other textbox in the PreRender event does not produce that error.
Please help.
Thank You
Mar 13 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.