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

Gridview in C# ASP.Net

Jay
Hi,
I am working in ASP.Net with C# as code behind.

Now i have provided a gridview and i have provided Checkbox and
connected SQL database in it .
it works fine... now i need to to do it in C# .. this is because wheni
click a button i need to display the data from the database .

how to do it? the one i have done is , it displays all the data when i
execute that page.

waiting for ur replay,

Thanks,
Jay

Aug 2 '06 #1
4 11582
The code you did in your page load, put it in a method, and call that method
in the page load after chekcing IsPostBack property is false.
Then add click event handler to you button, and call that method again in
the click event handler of the button

hope it helps
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Jay" wrote:
Hi,
I am working in ASP.Net with C# as code behind.

Now i have provided a gridview and i have provided Checkbox and
connected SQL database in it .
it works fine... now i need to to do it in C# .. this is because wheni
click a button i need to display the data from the database .

how to do it? the one i have done is , it displays all the data when i
execute that page.

waiting for ur replay,

Thanks,
Jay

Aug 2 '06 #2
Jay
Well dude,
I didn't write anything in my Post load function...
i need to know what i have to write in that ?

i tried this one:
code:
DataSet objDs = new DataSet();
System.Data.SqlClient.SqlConnection
myConnection = new

System.Data.SqlClient.SqlConnection(System.Configu ration.ConfigurationManager.ConnectionStrings["JConnectionString"].ConnectionString);
System.Data.SqlClient.SqlDataAdapter
myCommand;
myCommand = new

System.Data.SqlClient.SqlDataAdapter("StoredProced ure1",myConnection);
myCommand.SelectCommand.CommandType =
CommandType.StoredProcedure;
myConnection.Open();
myCommand.Fill(objDs);

GridView2.DataSource = objDs;
GridView2.DataBind();

but i end up in getting error in this ( GridView2.DataBind(); ) line.

this is the error :
"A field or property with the name 'id' was not found on the selected
data source."

is there any way to get rid of this error.?

Thanks,
Jay


Muhammad Mosa wrote:
The code you did in your page load, put it in a method, and call that method
in the page load after chekcing IsPostBack property is false.
Then add click event handler to you button, and call that method again in
the click event handler of the button

hope it helps
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Jay" wrote:
Hi,
I am working in ASP.Net with C# as code behind.

Now i have provided a gridview and i have provided Checkbox and
connected SQL database in it .
it works fine... now i need to to do it in C# .. this is because wheni
click a button i need to display the data from the database .

how to do it? the one i have done is , it displays all the data when i
execute that page.

waiting for ur replay,

Thanks,
Jay
Aug 2 '06 #3
Go to your gridview design or script. you will find that you are trying to
bind a field named id, which is not part of the selected result. Also you
will need to check your stored procedure to make sure that this field exists
or exists with another name.
Also don't forget to close your connection after filling your datasets

Reagrds
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Jay" wrote:
Well dude,
I didn't write anything in my Post load function...
i need to know what i have to write in that ?

i tried this one:
code:
DataSet objDs = new DataSet();
System.Data.SqlClient.SqlConnection
myConnection = new

System.Data.SqlClient.SqlConnection(System.Configu ration.ConfigurationManager.ConnectionStrings["JConnectionString"].ConnectionString);
System.Data.SqlClient.SqlDataAdapter
myCommand;
myCommand = new

System.Data.SqlClient.SqlDataAdapter("StoredProced ure1",myConnection);
myCommand.SelectCommand.CommandType =
CommandType.StoredProcedure;
myConnection.Open();
myCommand.Fill(objDs);

GridView2.DataSource = objDs;
GridView2.DataBind();

but i end up in getting error in this ( GridView2.DataBind(); ) line.

this is the error :
"A field or property with the name 'id' was not found on the selected
data source."

is there any way to get rid of this error.?

Thanks,
Jay


Muhammad Mosa wrote:
The code you did in your page load, put it in a method, and call that method
in the page load after chekcing IsPostBack property is false.
Then add click event handler to you button, and call that method again in
the click event handler of the button

hope it helps
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Jay" wrote:
Hi,
I am working in ASP.Net with C# as code behind.
>
Now i have provided a gridview and i have provided Checkbox and
connected SQL database in it .
it works fine... now i need to to do it in C# .. this is because wheni
click a button i need to display the data from the database .
>
how to do it? the one i have done is , it displays all the data when i
execute that page.
>
waiting for ur replay,
>
Thanks,
Jay
>
>

Aug 2 '06 #4
Jay
Ya thats fine.. thanks a lot Muhammad Mosa ...

great dude...

Thanks once again,
Jayender

Muhammad Mosa wrote:
Go to your gridview design or script. you will find that you are trying to
bind a field named id, which is not part of the selected result. Also you
will need to check your stored procedure to make sure that this field exists
or exists with another name.
Also don't forget to close your connection after filling your datasets

Reagrds
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"Jay" wrote:
Well dude,
I didn't write anything in my Post load function...
i need to know what i have to write in that ?

i tried this one:
code:
DataSet objDs = new DataSet();
System.Data.SqlClient.SqlConnection
myConnection = new

System.Data.SqlClient.SqlConnection(System.Configu ration.ConfigurationManager.ConnectionStrings["JConnectionString"].ConnectionString);
System.Data.SqlClient.SqlDataAdapter
myCommand;
myCommand = new

System.Data.SqlClient.SqlDataAdapter("StoredProced ure1",myConnection);
myCommand.SelectCommand.CommandType =
CommandType.StoredProcedure;
myConnection.Open();
myCommand.Fill(objDs);

GridView2.DataSource = objDs;
GridView2.DataBind();

but i end up in getting error in this ( GridView2.DataBind(); ) line.

this is the error :
"A field or property with the name 'id' was not found on the selected
data source."

is there any way to get rid of this error.?

Thanks,
Jay


Muhammad Mosa wrote:
The code you did in your page load, put it in a method, and call that method
in the page load after chekcing IsPostBack property is false.
Then add click event handler to you button, and call that method again in
the click event handler of the button
>
hope it helps
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
>
>
"Jay" wrote:
>
Hi,
I am working in ASP.Net with C# as code behind.

Now i have provided a gridview and i have provided Checkbox and
connected SQL database in it .
it works fine... now i need to to do it in C# .. this is because wheni
click a button i need to display the data from the database .

how to do it? the one i have done is , it displays all the data when i
execute that page.

waiting for ur replay,

Thanks,
Jay
Aug 3 '06 #5

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

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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...
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
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.