标题:求助GridView不能更新
只看楼主
yph1331
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-11-6
 问题点数:0 回复次数:0 
求助GridView不能更新
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using weblibrary.data;

public partial class _Default : System.Web.UI.Page
{
    private SqlDataAdapter da;
    private DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        getInfo();
      
    }

    private void getInfo()
    {
        string str = "Data Source = .;Initial Catalog = library; User Id = sa;Password = 123";
        string sql = "select * from LB_FLXX";
        SqlConnection conn = new SqlConnection(str);
        da = new SqlDataAdapter(sql, conn);
        da.Fill(ds, "t");
        GridView1.DataSource = ds.Tables["t"];
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        getInfo();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlCommandBuilder cb = new SqlCommandBuilder(da);
        da.Update(ds, "t");
        GridView1.EditIndex = -1;
        getInfo();
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        getInfo();
    }
}
搜索更多相关主题的帖子: GridView 
2008-11-06 14:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-242734-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.190985 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved