473,387 Members | 3,801 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,387 software developers and data experts.

why error with RowDataBound event and not with RowCreated?

Ben
Hi,

Can someone explain me why the same code with the event
GridView1_RowDataBound gives this error:

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

and not with the event GridView1_RowCreated ?

Thanks
Ben

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then
Dim dd As DropDownList
Dim i As Integer
Dim z As ListItem
dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i, i)
dd.Items.Add(z)
Next
End If
End If
End Sub

Jun 27 '08 #1
2 2961
Is the error caused by this code or by some other code or settings not
included in your post? In the former case, on what line? How does the
template look like?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Ben" <be*@nol.vbwrote in message
news:em**************@TK2MSFTNGP05.phx.gbl...
Hi,

Can someone explain me why the same code with the event
GridView1_RowDataBound gives this error:

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

and not with the event GridView1_RowCreated ?

Thanks
Ben

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then
Dim dd As DropDownList
Dim i As Integer
Dim z As ListItem
dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i, i)
dd.Items.Add(z)
Next
End If
End If
End Sub

Jun 27 '08 #2
Ben
By this code. The reason is that the selectedvalue in the aspx file requires
too early a value which is only provided at rowdatabound event.

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschree f in
bericht news:eU**************@TK2MSFTNGP06.phx.gbl...
Is the error caused by this code or by some other code or settings not
included in your post? In the former case, on what line? How does the
template look like?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Ben" <be*@nol.vbwrote in message
news:em**************@TK2MSFTNGP05.phx.gbl...
>Hi,

Can someone explain me why the same code with the event
GridView1_RowDataBound gives this error:

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

and not with the event GridView1_RowCreated ?

Thanks
Ben

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As

System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then
Dim dd As DropDownList
Dim i As Integer
Dim z As ListItem
dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i, i)
dd.Items.Add(z)
Next
End If
End If
End Sub


Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MasterChief | last post by:
I am trying to add an attribute to a gridview row so when you click on it, it will pop up an alert saying the current datakey for that row. How is it possible to get a datakey when using the...
0
by: danc | last post by:
I am trying to modify the layout of a row based on the value in some data (I am creating a subtotal line). This works fine when the page is first loaded, but when it's reloaded, the wrong column is...
0
by: tfsmag | last post by:
I'm having a weird problem with the rowdatabound event for a gridview in my application... Here is the code. -------------------------------------- Protected Sub AnswersGrid_RowDataBound(ByVal...
3
by: K B | last post by:
Hi again, I've narrowed down my problem and am hoping to get some help to get the final answer. Gridview with dynamic child controls loads gv1.Databind calls RowDataBound event fine On the...
3
by: ryan.mclean | last post by:
Hello everyone, I'm in a bind, and I hope somebody can point me in the right direction. I have a gridview that is bound when it is not a postback. When the grid is bound, I remove the contents...
4
by: GaryDean | last post by:
I'm up against something else I used to easily do in a DataGrid that is different in a GridView.... I used to access cells in non-visible columns in the ItemDataBound event. The data was there -...
2
by: Tim | last post by:
I'm using a GridView with its DataSource property set to a DataTable. During the RowDataBound event, the first row of the DataTable is reported as a DataControlRowType.Header instead of...
0
gchq
by: gchq | last post by:
Hi there Bringing a large chunk of records into a Gridview, then making a seperate database call for each record in the RowDataBound event is quite time consuming - so I have tried to launch this...
0
by: Bogdan | last post by:
Hi, I need to modify gridview footer so it consists only of a single column that spans all data columns in a gridview. I first tried DataBound() event (as per suggestion found on the Net) but...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.