Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...

I am working with repeater control..
Inside repeater control I have a link button and other controls like radiobuttonlist and textboxes
I want to write code as if user click on link button inside repeater then all values fron other controls inside the repeater should be saved somewhere

I wrote this code in ItemCommand event and access other control like

VB
Dim txtStart As TextBox = TryCast(e.Item.FindControl("txtdate"), TextBox)

ans accessing its text property as
VB
Dim s As String = txtStart.Text


its working fine...

but as I access other control like dropdownlist and use its property it gives exception
object reference not set to instant of object

VB
Dim ddlTenure As DropDownList = TryCast(e.Item.FindControl("drp1"), DropDownList)

VB
Dim a As String=ddlTenure.SelectedItem.Text


please try to resolve
thanks
Posted
Comments
Aravindba 23-Oct-13 5:42am    
may be in dropdown list u cant get any value, may be null,or just use
Dim a As String=ddlTenure.Text or did u bind id in dropdown list ?
Zafar Sultan 23-Oct-13 5:44am    
What about inserting a breakpoint at Dim ddlTenure As DropDownList.... and debug? You might come across the line causing trouble.

Item does not exists in the drop down list so it is giving an error. first initialize drop down then try to execute code. it will work.

Regards.
 
Share this answer
 
Try this
C#
Dim ddlTenure As DropDownList = DirectCast(e.Item.FindControl("drp1"), DropDownList)

Dim a As String=ddlTenure.SelectedValue

Regards..
 
Share this answer
 
Comments
[no name] 23-Oct-13 6:04am    
Thank you sir...
Check your item names: does "drp1" exist?
If it does, then split your lines, and check each part in turn:
VB
Dim obj = e.Item.FindControl("drp1")
Is obj equal to Nothing? If it is double check the name!
If not, then
VB
Dim ddlTenure As DropDownList = TryCast(obj, DropDownList)
Is ddlTenure equal to Nothing? If it is, then you need to check the actual type of the dropdown and correct that.
Finally, check ddlTenure.SelectedItem against Nothing - if there is nothing selected, that will be your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900