1
votes

I have a gridview - GridView1.
I am adding rows to this Gridview1 dyanamically through code.
One of the columns is a dropdownlist that reads from a sqldatasource.
The textboxes, dropdownlists & sql datasources are all arrays.
If I change the value of the dropdownlist, it maintains its state even after the page reloads on any button click event. This is ok. However, the values of the textboxes are not maintained.
Say I enter "Hello World" in the textbox & click "Add" button, I want to collect the text value in dropdownlist(which I can read) & the value in textbox(which returns blank.) Please suggest a method so that on add button click I can retrive the value I had typed in the textbox. Each textbox has a unique id & I tried using the ID to get its value
eg
protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) handles add.click
{
Dim valueinText = gettext(1).text }
now if I type "Hello World" in textbox: gettext(1),
Reults: valueinText = ""

Thanks in advance

2

2 Answers

1
votes

You will have to reset the values for unbound textboxes that get their value from code when you post back. In your Page Load Event...

If Page.IsPostback Then

   'Code that uses dropdownlistAtoZ.SelectedValue
   'to fill in correct value for Textboxes.

End If
0
votes

I was trying to create the same textboxes on every page_load event. But this just erased their values & their client_ID kept changing.

Instead, I tried making all textboxes Shared and created them only once on add click event, added them to a Row (which is again shared) and on page_load if page.postback = true I just added the row to the table again. If you don't do so, the row will not be shown on reload.

This solved my problem(now the values entered in Textbox were not cleared like before). I accessed the value by classname.textboxname(i).text.

Now the solution seems obvious, but I spent a few days trying to solve this.

Thanks!