Click here to Skip to main content
12,944,121 members (56,647 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Rate this: bad
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();
                SqlDataAdapter adapter = new SqlDataAdapter(command);
catch (Exception ex)
              //handle the error message here

Then to bind Gridview:

Note I am not using conn.Open(), because the Fill() method will do that, according to msdn reference:[^]
Rate this: bad
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

S4nd1p 6-Jan-13 2:21am
plz can u explain its urgent for me !!!!!
Sandeep Mewara 6-Jan-13 2:25am
I have explained. If it's urgent, act on the steps mentioned quickly to get going.
S4nd1p 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
Top Experts
Last 24hrsThis month
OriginalGriff 4,653
CHill60 2,970
Maciej Los 2,388
Jochen Arndt 1,900
ppolymorphe 1,765

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2017
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