【问题标题】:radgridview delete update in asp.netradgridview 在 asp.net 中删除更新
【发布时间】:2011-02-19 01:19:09
【问题描述】:

我已经编写了以下代码来显示来自数据网格的数据并插入新行但是我如何执行更新和删除请帮助这是我的代码 使用系统; 使用 System.Data; 使用 System.Configuration; 使用 System.Collections; 使用 System.Web; 使用 System.Web.Security; 使用 System.Web.UI; 使用 System.Web.UI.WebControls; 使用 System.Web.UI.WebControls.WebParts; 使用 System.Web.UI.HtmlControls; 使用 Telerik.Web.UI; 使用 System.Data.SqlClient;

公共部分类 Default6 : System.Web.UI.Page { 字符串 strQry, strCon;

SqlDataAdapter da;
SqlConnection con;
DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
    strCon = "Data Source=MINETDEVDATA; Initial Catalog=ML_SuppliersProd; User Id=sa; Password=@MinetApps7;";
    con = new SqlConnection(strCon);
    strQry = "SELECT * FROM table1";
    da = new SqlDataAdapter(strQry, con);
    SqlCommandBuilder cmdbuild = new SqlCommandBuilder(da);
    ds = new DataSet();
    da.Fill(ds, "table1");
    RadGrid1.DataSource = ds.Tables["table1"];
    RadGrid1.DataBind();
    Label3.Visible = false;
    Label4.Visible = false;
    Label5.Visible = false;
    txtFname.Visible = false;
    txtLname.Visible = false;
    txtDesignation.Visible = false;

}
protected void Submit_Click(object sender, EventArgs e)
{
    Label3.Visible = true;
    Label4.Visible = true;
    Label5.Visible = true;
    txtFname.Visible = true;
    txtLname.Visible = true;
    txtDesignation.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
    DataSet ds = new DataSet("EmployeeSet");
    da.Fill(ds, "table1");



    DataTable EmployeeTable = ds.Tables["table1"];
    DataRow row = EmployeeTable.NewRow();
    row["Fname"] = txtFname.Text.ToString();
    row["Lname"] = txtLname.Text.ToString();
    row["Designation"] = txtDesignation.Text.ToString();
    EmployeeTable.Rows.Add(row);
    da.Update(ds, "table1");
    //RadGrid1.DataSource = ds.Tables["table1"];
    //RadGrid1.DataBind();
    txtFname.Text = "";
    txtLname.Text = "";
    txtDesignation.Text = "";


}






protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
{


    }
}

}

【问题讨论】:

    标签: c# asp.net sql


    【解决方案1】:

    当您分配 EmployeeTable 类型的新行时,您可以将任何选定的行分配给数据行,然后进行更改。

    DataTable EmployeeTable = ds.Tables["table1"];  
    DataRow row = EmployeeTable.rows[Radgrid.selectedIndex];  
    row["Fname"] = txtFname.Text.ToString();  
    row["Lname"] = txtLname.Text.ToString();  
    row["Designation"] = txtDesignation.Text.ToString();  
    EmployeeTable.Rows.Add(row);  
    da.Update(ds, "table1");  
    

    试试这个。我还没有测试过,但这应该可以。

    【讨论】:

      【解决方案2】:

      您可以在此使用对象数据源来选择删除和​​更新方法

      您可以拖放一个对象数据源,然后对其进行配置。

      & 将 objectDatasource 提供给 Grid。

      &您可以将方法放在不同的层上,例如业务逻辑层..& 然后您可以将这些方法提供给对象数据源

      &您可以通过表的主键连接OBjectDataSource和网格。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多