473,387 Members | 1,440 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,387 software developers and data experts.

Binding GridView with code-behind

Hello,

I have a GridView that is using the following to connect to a SQL Server
2000 stored procedure:

<asp:SqlDataSource
ID="dsWebDocList" SelectCommand="sp_web_WebDocument"
ConnectionString="<%$ ConnectionStrings:cnnSQL_Connect %>" Runat="server">
<SelectParameters>
<asp:Parameter Type="String" DefaultValue="FindWebDocAll"
Name="strParm01"></asp:Parameter>
<asp:Parameter Type="String" DefaultValue="Interlock"
Name="strParm02"></asp:Parameter>
<asp:Parameter Type="String" DefaultValue="1-1-2000"
Name="strParm03"></asp:Parameter>
<asp:Parameter Type="String" DefaultValue="NoParameter"
Name="strParm04"></asp:Parameter>
<asp:Parameter Type="String" DefaultValue="NoParameter"
Name="strParm05"></asp:Parameter>
</SelectParameters>
</asp:SqlDataSource>

But for all my other controls, I am using code-behind and using something
like the following:
'Populate the GridView combo box
'------------------------------
Dim spGridView As OleDb.OleDbDataReader
Dim prmGridView As OleDbParameter
Dim cmdGridView As New OleDb.OleDbCommand("sp_web_WebDocument",
cnnSearch)
cmdGridView.CommandType = CommandType.StoredProcedure

'Declare Parameters
prmGridView = cmdGridView.Parameters.Add("@strParm01",
OleDbType.VarChar) : prmGridView.Value = "FindWebDocAll"
prmGridView = cmdGridView.Parameters.Add("@strParm02",
OleDbType.VarChar) : prmGridView.Value = "Interlock"
prmGridView = cmdGridView.Parameters.Add("@strParm03",
OleDbType.VarChar) : prmGridView.Value = "1-1-2000"
prmGridView = cmdGridView.Parameters.Add("@strParm04",
OleDbType.VarChar) : prmGridView.Value = "NoParameter"
prmGridView = cmdGridView.Parameters.Add("@strParm05",
OleDbType.VarChar) : prmGridView.Value = "NoParameter"

'Data Bind: DropdownList
spGridView = cmdGridView.ExecuteReader()

The problem I am having is that I can't bind the data to the GridView. I am
using the following:

'Data Bind: DropdownList
spGridView = cmdGridView.ExecuteReader()
gvWebDocList.DataSourceID = spGridView
gvWebDocList.DataBind()

Any help with this would be appreciated.

Thanks in advance, sck10


Nov 18 '05 #1
5 18510
Hi sck10,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 18 '05 #2
Hi Sck10,

From your description and the code snippet you provided, it seems that
you're assigning the retrieved DataReader object to the DropDownList's
datasource, yes? If so, I think we should try binding the DataReader to the
GridView directly rather than the dropdownlist, the dropdownlist is just a
helper control for selecting tables. The actual datasource should be the
GRidView's DataSource, we should bind the data we retrieved to the
GridView. You may have a try to see whether this is the cause. Also, if
you meet any further problem, you can also have a look in the .net's
Whidbey newsgroup for some more specific guides:

http://communities.microsoft.com/new...idbey&slcid=us

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #3
Hi Steve,

The problem I am having is trying to find the syntac for binding a GridView
using CodeBehind. I am unable to set the DataSourceID to the
OleDbDataReader. Am I setting the wrong method(?)?

Thanks, Steven
'Populate the GridView combo box
'------------------------------
Dim spGridView As OleDb.OleDbDataReader
Dim prmGridView As OleDbParameter
Dim cmdGridView As New
OleDb.OleDbCommand("sp_web_WebDocument",cnnSearch)
cmdGridView.CommandType = CommandType.StoredProcedure

'Declare Parameters
prmGridView = cmdGridView.Parameters.Add("@strParm01",OleDbType. VarChar)
: prmGridView.Value = "FindWebDocAll"
prmGridView = cmdGridView.Parameters.Add("@strParm02",OleDbType. VarChar)
: prmGridView.Value = "Interlock"
prmGridView = cmdGridView.Parameters.Add("@strParm03",OleDbType. VarChar)
: prmGridView.Value = "1-1-2000"
prmGridView = cmdGridView.Parameters.Add("@strParm04",OleDbType. VarChar)
: prmGridView.Value = "NoParameter"
prmGridView = cmdGridView.Parameters.Add("@strParm05",OleDbType. VarChar)
: prmGridView.Value = "NoParameter"

'Data Bind: GridView
spGridView = cmdGridView.ExecuteReader()
gvWebDocList.DataSourceID = spGridView
gvWebDocList.DataBind()

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:WN**************@cpmsftngxa10.phx.gbl...
Hi Sck10,

From your description and the code snippet you provided, it seems that
you're assigning the retrieved DataReader object to the DropDownList's
datasource, yes? If so, I think we should try binding the DataReader to the GridView directly rather than the dropdownlist, the dropdownlist is just a
helper control for selecting tables. The actual datasource should be the
GRidView's DataSource, we should bind the data we retrieved to the
GridView. You may have a try to see whether this is the cause. Also, if
you meet any further problem, you can also have a look in the .net's
Whidbey newsgroup for some more specific guides:

http://communities.microsoft.com/new...idbey&slcid=us
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Hi Sck10,

Thank for your response. From my research, the ASP.NET 2.0's GridView
Control is different from the DataGrid/DataList Controls in asp.net 1.1.
The GridView must stand upon a DataSourceControl , so I think if we want to
programmly bind data to GridView Control, we need to programly create a new
DAtaSourceControl( add into the page) first and assign the
DataSourceControl's ID to that GridView Control.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5

I am having an issue that is similar.

I have a page that needs to build a complex where clause and return the
results into a gridview. After i bind the data no results are returned,
even when the sql statement (a select statement) returns data. I have
tried something similar with an objectdatasource also but it shows the
same thind.

Here is my code

// m_sds is a sqldatasource object, with the connection, and mode
(dataset) set declaritively
// m_gv is my gridview control
m_sds.SelectCommand = sql;
m_sds.DataSourceMode = SqlDataSourceMode.DataSet;
m_gv.DataSourceID = m_sds.ID;
m_gv.DataBind();
refresh_page();
Steven Cheng[MSFT] wrote:
*Hi Sck10,

Thank for your response. From my research, the ASP.NET 2.0's
GridView
Control is different from the DataGrid/DataList Controls in asp.net
1.1.
The GridView must stand upon a DataSourceControl , so I think if we
want to
programmly bind data to GridView Control, we need to programly create
a new
DAtaSourceControl( add into the page) first and assign the
DataSourceControl's ID to that GridView Control.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers
no
rights.) *


--
lewisv
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 16 '06 #6

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

Similar topics

9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
1
by: Smash | last post by:
I have problem binding gridview.... At first i didn't want to bind gridview at first page load...so in my objectdatasource_selecting event i wrote this: If Not Page.IsPostBack Then e.Cancel =...
3
by: mateo | last post by:
Hello, I have a GridView inside which i want to show 3 dropdownList (one for each Column). So i've created 3 TemplateField Continent Country City
5
by: Amit | last post by:
Hello, I have a simple search screen, with two drop-downs and a text box. There's also a GridView control that is using a SqlDataSource control to show the matching results. The SqlDataSource uses...
5
by: GaryDean | last post by:
I have a GridView that works fine when I bind it to an ObjectDataSource at design time. But if I bind it at run time nothing happens. On a button click event I say... GridView1.DataSourceID =...
8
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The...
4
by: Mike | last post by:
I'm having trouble getting a gridview to bind. I probably missing something completely obvious and would appreciate any help on offer. I'm passing parameters via querystring, and have created a...
1
by: Monty M. | last post by:
Does anyone know how to perform two way data binding between a combo box and a listview. The listview is bound to a dataset table in code: Binding Bind = new Binding(); DataTable dt;...
3
by: RobertTheProgrammer | last post by:
Hi folks, I've got another problem. Basically, I'm trying to use a nested GridView, however the nexted GridView displays no values (even though in debug I'm getting valid values into my DataSet. ...
0
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.