Programmatically populate a GridView

J

John Straumann

Hello all:

I am trying to populate a GridView with data being read from a call to a web
service. I have seen plenty of examples that simply execute a SQL data
reader, set the Grid data source to the reader, and then call DataBind(),
but I cannot seem to figure out how to build the GridView row by row with
anything except text. I need the 2nd column of the Grid to be a hyperlink or
a button, and this is where I am having an issue. I can build the Grid by
creating a new data table, adding to the data table column by column and
then row by row, and then binding the Grid to the new Data table, but this
only shows plain text.

Using the designer I also tried creating 3 columns in the Grid, the first
one as text, the 2nd as a ButtonField (I also tried a hyperlink), and the
3rd as text, but when I ran the page I ended up with 6 columns, and the ones
I had created in the designer were empty.

I also tried creating a HyperlinkField and also a ButtonField and setting
the cells in the 2nd column to that, but that did not work either.

Any and all advice is greatly appreciated.

John.
 
M

Manish

Hi John,

As far as 6 columns are concerned even though you are adding 3 columns. for
this, you will have to set the AutoGenerateColumns property of the GridView
to false.

And to show hyperlink in one of thet column, you will have to add the
TemplateField in your grid rather than BoundField and then add the Hyperlink
control in the ItemTemplate of that TemplateField column.

Regards,
Manish
www.componentone.com
 
J

John Straumann

Hi Manish:

Thanks for your note. Do you know of a site that shows an example and/or
tutorial covering this topic?

John.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top