This is a migrated thread and some comments may be shown as answers.

Save button outside of RagGrid ?

1 Answer 22 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Venkata
Top achievements
Rank 1
Venkata asked on 22 Jul 2013, 12:40 PM
Hello All,

I am trying to update records in the gridview through "Save" button, and save button is outside of GridView. The problem is with the paging.
When i update records using save button, it is updating records, but paging is not working properly. The next page is showing blank.

protected void Page_Load(object sender, EventArgs e)

{

if(!IsPostBack){

con.Open();

 

 

SqlCommand cmd = new SqlCommand("select * from MyTable", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

con.Close();

RadGrid1.DataSource = ds;

RadGrid1.DataBind();
}
}

And
protected void btnSave_Click(object sender, EventArgs e)

{

 

foreach (GridDataItem gvr in RadGrid1.Items)

{

 

TextBox UpdateID = gvr["ID"].FindControl("txtID") as TextBox;

TextBox UpdateName = gvr["Name"].FindControl("txtName") as TextBox;

TextBox UpdateDept = gvr["Dept"].FindControl("txtDept") as TextBox;

con.Open();

 

SqlCommand cmd = new SqlCommand("update MyTable set Name = '" + UpdateName.Text + "', Dept = '" + UpdateDept.Text + "'where ID = " + UpdateID.Text, con);

cmd.ExecuteNonQuery();

con.Close();

 

lblresult.Text = " Details Updated successfully";

}

 
Can you suggest me how can i resolve this?
Thanks,
Venkata.

}

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 22 Jul 2013, 12:46 PM
Hi Venkata,

You can use Advanced Data Binding to achieve your requirement. Please have a look at this documentation on Grid Advanced Data Binding.

Thanks,
Shinu.
Tags
General Discussions
Asked by
Venkata
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or