Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In my asp.net iwant to get gridview data in a dataset how to do this

any one please help me.....
Posted
Comments
Prasad_Kulkarni 24-Aug-12 2:29am    
You've already ask'd this question:
how to get gridview data in dataset in asp.net[^]
Don't re-post your questions, If you want to modify or update your question then use 'Improve question' widget. But don't re-post it.

Remove one of the entry.

Have a look on this

C#
DataTable dt = new DataTable();

    // add the columns to the datatable            
    if (GridView1.HeaderRow != null)
    {

        for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
        {
            dt.Columns.Add(GridView1.HeaderRow.Cells[i].Text);
        }
    }

    //  add each of the data rows to the table
    foreach (GridViewRow row in GridView1.Rows)
    {
        DataRow dr;
        dr = dt.NewRow();

        for (int i = 0; i < row.Cells.Count; i++)
        {
            dr[i] = row.Cells[i].Text.Replace(" ","");
        }
        dt.Rows.Add(dr);
    }

    //  add the footer row to the table
    if (GridView1.FooterRow != null)
    {
        DataRow dr;
        dr = dt.NewRow();

        for (int i = 0; i < GridView1.FooterRow.Cells.Count; i++)
        {
            dr[i] = GridView1.FooterRow.Cells[i].Text.Replace(" ","");
        }
        dt.Rows.Add(dr);
    }
 
Share this answer
 
Try this...


Gridview data in dataset

DataSet ds = (DataSet)Gridview1.DataSource;

Get data from database and populate to gridview
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlDataReader rd;
SqlCommand cmd = new SqlCommand("Select * from tablename", con);
rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
rd.Close();
con.Close();


In aspx page
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown"> 
</asp:gridview>


Hope this helps.
cheers
 
Share this answer
 
v3
hi

used below,

DataSet tbl = GrdCCCSList.DataSource as DataSet; 


hope this will help you
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900