473,725 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:SqlDataSou rce
ID="dsWebDocLis t" SelectCommand=" sp_web_WebDocum ent"
ConnectionStrin g="<%$ ConnectionStrin gs:cnnSQL_Conne ct %>" Runat="server">
<SelectParamete rs>
<asp:Paramete r Type="String" DefaultValue="F indWebDocAll"
Name="strParm01 "></asp:Parameter>
<asp:Paramete r Type="String" DefaultValue="I nterlock"
Name="strParm02 "></asp:Parameter>
<asp:Paramete r Type="String" DefaultValue="1-1-2000"
Name="strParm03 "></asp:Parameter>
<asp:Paramete r Type="String" DefaultValue="N oParameter"
Name="strParm04 "></asp:Parameter>
<asp:Paramete r Type="String" DefaultValue="N oParameter"
Name="strParm05 "></asp:Parameter>
</SelectParameter s>
</asp:SqlDataSour ce>

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.OleDbData Reader
Dim prmGridView As OleDbParameter
Dim cmdGridView As New OleDb.OleDbComm and("sp_web_Web Document",
cnnSearch)
cmdGridView.Com mandType = CommandType.Sto redProcedure

'Declare Parameters
prmGridView = cmdGridView.Par ameters.Add("@s trParm01",
OleDbType.VarCh ar) : prmGridView.Val ue = "FindWebDoc All"
prmGridView = cmdGridView.Par ameters.Add("@s trParm02",
OleDbType.VarCh ar) : prmGridView.Val ue = "Interlock"
prmGridView = cmdGridView.Par ameters.Add("@s trParm03",
OleDbType.VarCh ar) : prmGridView.Val ue = "1-1-2000"
prmGridView = cmdGridView.Par ameters.Add("@s trParm04",
OleDbType.VarCh ar) : prmGridView.Val ue = "NoParamete r"
prmGridView = cmdGridView.Par ameters.Add("@s trParm05",
OleDbType.VarCh ar) : prmGridView.Val ue = "NoParamete r"

'Data Bind: DropdownList
spGridView = cmdGridView.Exe cuteReader()

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.Exe cuteReader()
gvWebDocList.Da taSourceID = spGridView
gvWebDocList.Da taBind()

Any help with this would be appreciated.

Thanks in advance, sck10


Nov 18 '05 #1
5 18539
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.OleDbData Reader
Dim prmGridView As OleDbParameter
Dim cmdGridView As New
OleDb.OleDbComm and("sp_web_Web Document",cnnSe arch)
cmdGridView.Com mandType = CommandType.Sto redProcedure

'Declare Parameters
prmGridView = cmdGridView.Par ameters.Add("@s trParm01",OleDb Type.VarChar)
: prmGridView.Val ue = "FindWebDoc All"
prmGridView = cmdGridView.Par ameters.Add("@s trParm02",OleDb Type.VarChar)
: prmGridView.Val ue = "Interlock"
prmGridView = cmdGridView.Par ameters.Add("@s trParm03",OleDb Type.VarChar)
: prmGridView.Val ue = "1-1-2000"
prmGridView = cmdGridView.Par ameters.Add("@s trParm04",OleDb Type.VarChar)
: prmGridView.Val ue = "NoParamete r"
prmGridView = cmdGridView.Par ameters.Add("@s trParm05",OleDb Type.VarChar)
: prmGridView.Val ue = "NoParamete r"

'Data Bind: GridView
spGridView = cmdGridView.Exe cuteReader()
gvWebDocList.Da taSourceID = spGridView
gvWebDocList.Da taBind()

"Steven Cheng[MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:WN******** ******@cpmsftng xa10.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 DataSourceContr ol , so I think if we want to
programmly bind data to GridView Control, we need to programly create a new
DAtaSourceContr ol( add into the page) first and assign the
DataSourceContr ol'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 objectdatasourc e 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.SelectCom mand = sql;
m_sds.DataSourc eMode = SqlDataSourceMo de.DataSet;
m_gv.DataSource ID = 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 DataSourceContr ol , so I think if we
want to
programmly bind data to GridView Control, we need to programly create
a new
DAtaSourceContr ol( add into the page) first and assign the
DataSourceContr ol'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
5336
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 (filtered) dependent upon the selection in DDL1. I think this inevitably needs some code, but I'd be happy to be told otherwise! I have some code to handle OnSelectedIndexChanged for DDL1 that sets the FilterExpression associated with the...
1
2030
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 = True End If Thats solved the problem for the first bind....
3
6992
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
11221
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 the control values in its query as parameters. Two questions: 1. When the Find button is clicked, how do I tell the GridView to load the data? 2. How do I stop the GridView from data binding when the page first loads? I don't want to...
5
2805
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 = ObjectDataSource1.ID; GridView1.DataBind(); What's missing? --
8
8533
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 gridview's databind method is apparently called when the page is loaded as I have no code calling the databind method. How can I keep the gridview from databinding automatically and control it myself?
4
2606
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 stored proc as follows: qGetSearchResults: SELECT Adverts.AdvertID,
1
9839
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; Field_LV.DataContext = dt; Field_LV.SetBinding(ListView.ItemsSourceProperty, Bind);
3
2650
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. It's probably a binding issue somewhere, but I'm not sure where. Here's the ASP (slightly edited to remove verbosity): <asp:GridView ID="GridViewMain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" ...
0
1529
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 the Gridview control also .Actually I am able to bind the sql datasource control to the Gridview on button Click but on clicking the GridView for paging or sorting , the Gridview vanishes!! In short, I want to bind the GridView control to a...
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.