473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Programmatically populate a GridView

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.

Jun 27 '08 #1
2 6368
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
"John Straumann" wrote:
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.

Jun 27 '08 #2
Hi Manish:

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

John.

"Manish" <Ma****@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
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
"John Straumann" wrote:
>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.

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
I'm wondering if it's possible, outside of the declaration of an ASP.NET 2.0 GridView, to programmatically style individual columns. For example, I might want to make the text in a particular...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
0
by: jm | last post by:
I have a Gridview with a LinkButton. The button has text from my database. It is not the datakey of the database, just free form text. I want to populate another gridview based upon the data in...
1
by: rn5a | last post by:
I was using a DataView to bind records from a DB table to a DataGrid using the following code: Dim sqlDapter As SqlDataAdapter Dim dSet As DataSet Dim dView As DataView sqlDapter = New...
2
by: Wayne Deleer | last post by:
Hi All, I'm currently working on a project, and I've come to a part where I want to add data to a GridView. BUT, I want to do it programmatically, with alot of control over everything. In my...
0
by: cook.jonathan.m | last post by:
I want to programmatically add a dropdown to each row in a certain column returned to the gridview by my query. I want to do this entirely in behind-code. My gridview tag in the page will have...
1
by: =?Utf-8?B?UGF0cmljayBG?= | last post by:
I have a gridview on the page that i want to dynamically populate with radiobuttons, so i went out on the net and found something that works perfectly, it created radionuttons and the postback with...
4
by: Tomasz | last post by:
Hello Developers, Here is interesting problem I just came across: how do I wire a GridView control programmatically? Here is my sample code using Object Data Source: protected void...
5
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false"...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.