在我的asp.net中,我想在数据集中获取gridview数据,如何执行此操作 [英] In my asp.net iwant to get gridview data in a dataset how to do this

查看:83
本文介绍了在我的asp.net中,我想在数据集中获取gridview数据,如何执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net中,我想获取数据集中的gridview数据该怎么做

任何人都可以帮助我.....

In my asp.net iwant to get gridview data in a dataset how to do this

any one please help me.....

推荐答案

看看这个

Have a look on this

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);
    }


尝试一下...


数据集中的Gridview数据

DataSet ds =(DataSet)Gridview1.DataSource;

从数据库获取数据并填充到gridview
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();



在aspx页面中



In aspx page

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



希望这会有所帮助.
欢呼



Hope this helps.
cheers




在下面使用,

hi

used below,

DataSet tbl = GrdCCCSList.DataSource as DataSet; 



希望对您有帮助



hope this will help you


这篇关于在我的asp.net中,我想在数据集中获取gridview数据,如何执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆