Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:HiddenField ID="hdnCount" Value="1" runat="server" />



VB
Dim rowCount As Integer = Integer.Parse(hdnCount.Value)
       

      For rowNumber As Integer = 1 To rowCount 

            Dim name As TextBox = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("txtName" & rowNumber.ToString()), TextBox)
            
            Dim age As DropDownList = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("drdAge" & rowNumber.ToString()), DropDownList)
            Dim sex As DropDownList = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("drdSex" & rowNumber.ToString()), DropDownList)
            Dim mobileno As TextBox = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("txtmobileno" & rowNumber.ToString()), TextBox)
           
            lblDisplay.Text = name
           lblDisplay1.Text = age
lblDisplay2.Text = sex
lblDisplay3.Text = mobileno

        Next








the error for this code is "Object Reference is not set to an instance of an object"
here textbox does not retrieve the ID and gives the null value (nothing).

Please help for this query. Its very Urgent...!
Thank you in advance...!
Posted
Updated 19-May-13 19:45pm
v2

Thanks a lot....! Mahesh :-)
this solution was helpful...!
 
Share this answer
 
I think u forgot to use text property of textbox
example
name is textbox then at time of assigning value to lblDisplay u have to use
lblDisplay.Text = name.Text
 
Share this answer
 
I have faced the same problem long ago. Below is the approach I have used best to my knowledge

First you need to recreate your dynamic control on PostBack as they no longer exist.

Then to get value submitted by user you need to use following syntax

VB
Dim name As TextBox = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("txtName" & rowNumber.ToString()), TextBox)

name.Text = Request(name.UniqueID)


Hope this help and also let me know if you need some clarification
 
Share this answer
 
v2

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