开发者

radgridview delete update in asp.net

开发者 https://www.devze.com 2022-12-29 23:27 出处:网络
i have written the follwing to display data from the datagrid and den insert new rows but how do i perform update and delete plss help here\'s my code

i have written the follwing to display data from the datagrid and den insert new rows but how do i perform update and delete plss help here's my code 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 Telerik.Web.UI; using System.Data.SqlClient;

public partial class Default6 : System.Web.UI.Page { string strQry, strCon;

SqlDataAdapter da;
SqlConnection con;
DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
    strCon = "Data Source=开发者_Python百科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)
{


    }
}

}


You Can use Object Data Source in this for Select Delete and Update Methods

You can Drag drop an object data source & then Configure it.

& give the objectDatasource to Grid.

& You Can Put Methods on a Diffrent Layer Like Business Logic Layer..& then you can Give Those Method to Object Data Source

& You can Connect OBjectDataSource & Grid By Primary key Of Table.


As you assign the new row of type EmployeeTable, You can assign any selected row to datarow and then make the changes.

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

Try this. I have not tested it, but this should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消