edit data in the Repeater control [Resolved]

Posted by Saranya Boopathi under C# on 6/26/2013 | Points: 10 | Views : 861 | Status : [Member] | Replies : 2
Hi,
Is it possible to edit data in the Repeater control?

Saranya Boopathi


Responses

Posted by: Justshekhar123 on: 6/26/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi Saranya Boopathi ,

Yes it is possible to edit as well as delete the data in Repeater control,

SImply add one column for CheckboxList in your Repeater control . After that when a User can select those checkbox, Get the Row value of that selected check box By using RowCommand evnt.Please Review the following mentined sample code for your reference .

if (e.CommandName == "update")
{
SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand SqlCmd = new SqlCommand("update CPMEMBERS set Member=@Member, UpdatedType=@UpdatedType where id=@ID", SqlCnn);
SqlCmd.Parameters.Add("@Member", SqlDbType.VarChar).Value = txtName.Text;
SqlCmd.Parameters.Add("@UpdatedType", SqlDbType.VarChar).Value = ddlType.SelectedItem.Text;
SqlCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = e.CommandArgument;
try
{
SqlCnn.Open();
SqlCmd.ExecuteNonQuery();

}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
if (SqlCnn.State == ConnectionState.Open)
SqlCnn.Close();
}
BindRepeater();
}
if (e.CommandName == "delete")
{
SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand SqlCmd = new SqlCommand("delete CPMEMBERS where id=@ID", SqlCnn);
SqlCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = e.CommandArgument;
try
{
SqlCnn.Open();
SqlCmd.ExecuteNonQuery();

}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
if (SqlCnn.State == ConnectionState.Open)
SqlCnn.Close();
}
BindRepeater();
}


Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/27/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.c-sharpcorner.com/uploadfile/kannagoud/edit-update-delete-record-in-repeater-control/

If this post helps you mark it as answer
Thanks

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response