Tuesday, July 28, 2009

How do you get a value back from an html grid with asp.net and vb.net?

I am trying to get a value back from an html grid on an asp.net page. I want to get the details of the controls on the page that I have stored in the html grid. How would I loop though the contents of the grid so that I can get the values back from the html. I have converted the grid to run as a server control.

How do you get a value back from an html grid with asp.net and vb.net?
I'm not familiar with an HTML grid, are you using a Gridview? If so, you can loop through them as dynamic columns but this can cause problems in the future, I find it much better to convert them to Template Columns. Then assign a unique id to each of the controls. Once this is done you can use code like this to loop through and gather data:





Dim myRow as GridViewRow


For each rmyRw in Gridview1.Rows


dim myLabel as new Label


myLabel = myRow.Cells(3).FindControl("Label3")


response.write myLabel.Text


Next





In this example I have a Label in Column 3 with an ID of Label3. It loops through the gridview and writes the value of that label. This can be used for Text Boxes, Radio Buttons, Check Boxes, Drop Down Lists, etc... I use it all the time, it works great for me.

pollen

No comments:

Post a Comment