Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i need databind in a gridview. suppose i have 2 webpage 1st page is Default.aspx and another webpage is Default2.aspx. use Button on default.aspx and use Gridview on default2.aspx. when i click button data will bind from sqlquery and page will redirect to default2.aspx and databind with gridview.
Posted 4-Jan-13 4:09am
S4nd1p563
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need a DataSet or DataTable that can be binded with GridView.This code will be added in the Page_Load() of default2.aspx(according to your specification):
string query = "your query";
SqlCommand cmd = new SqlCommand(query, conn); //conn is your SqlConnection
DataTable results = new DataTable();
 
 try
            {
 
                SqlDataAdapter adapter = new SqlDataAdapter(command);
 
                adapter.Fill(results);
            }
catch (Exception ex)
            {
              //handle the error message here
            }
 
 
Then to bind Gridview:
GridView.DataSource=results;
GridView.DataBind();
 
Note I am not using conn.Open(), because the Fill() method will do that, according to msdn reference:http://msdn.microsoft.com/en-us/library/bh8kx08z.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

And the issue is?

It does not work like this here.
 
Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

 

For now, here are the steps:
1. Create a web application and add the two pages.
2. On page1, place a button and define it's click handler
3. In button click handler, redirect the page on second one.
4. On page2, get the data from DB using ADO.NET (using SQL query)
5. Bind the data retrieved to the grid
 
Done!
  Permalink  
Comments
S4nd1p at 6-Jan-13 2:21am
   
plz can u explain its urgent for me !!!!!
Sandeep Mewara at 6-Jan-13 2:25am
   
I have explained. If it's urgent, act on the steps mentioned quickly to get going.
S4nd1p at 6-Jan-13 2:44am
   
Sandeep Mewara
 
plzz give me a example

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 458
1 OriginalGriff 344
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100