Gridview in C# ASP.Net

  • Thread starter Thread starter Jay
  • Start date Start date
J

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
 
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
 
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.Configuration.ConfigurationManager.ConnectionStrings["JConnectionString"].ConnectionString);
System.Data.SqlClient.SqlDataAdapter
myCommand;
myCommand = new

System.Data.SqlClient.SqlDataAdapter("StoredProcedure1",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
 
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 said:
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.Configuration.ConfigurationManager.ConnectionStrings["JConnectionString"].ConnectionString);
System.Data.SqlClient.SqlDataAdapter
myCommand;
myCommand = new

System.Data.SqlClient.SqlDataAdapter("StoredProcedure1",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 said:
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
 
Ya thats fine.. thanks a lot Muhammad Mosa ...

great dude...

Thanks once again,
Jayender

Muhammad said:
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 said:
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.Configuration.ConfigurationManager.ConnectionStrings["JConnectionString"].ConnectionString);
System.Data.SqlClient.SqlDataAdapter
myCommand;
myCommand = new

System.Data.SqlClient.SqlDataAdapter("StoredProcedure1",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 said:
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


:

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
 

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

Back
Top