Hi nedash,
Please refer the below code and modify as per your requirement.
C#
protected void ImgIjad_Click(object sender, EventArgs e)
{
string group1 = string.Empty;
string group2 = string.Empty;
string group3 = string.Empty;
string group4 = string.Empty;
foreach (GridViewRow row in GrdMessage.Rows)
{
HtmlInputCheckBox checkbox = (row.FindControl("ChBpriceL") as HtmlInputCheckBox);
if (checkbox.Checked)
{
switch ((row.FindControl("lblID") as Label).Text)
{
case "1":
group1 = (row.FindControl("Lblname") as Label).Text.Trim();
break;
case "2":
group2 = (row.FindControl("Lblname") as Label).Text.Trim();
break;
case "3":
group3 = (row.FindControl("Lblname") as Label).Text.Trim();
break;
case "4":
group4 = (row.FindControl("Lblname") as Label).Text.Trim();
break;
}
}
}
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("phoneBook_insert", conn))
{
conn.Open();
_cmd.Parameters.AddWithValue("@Name", Txtname.Text);
_cmd.Parameters.AddWithValue("@Address", Txtadd.Text);
_cmd.Parameters.AddWithValue("@Description", Txtdes.Text);
_cmd.Parameters.AddWithValue("@Mobile1", Txtmob1.Text);
_cmd.Parameters.AddWithValue("@Mobile2", Txtmob2.Text);
_cmd.Parameters.AddWithValue("@PhoneHome1", Txttell.Text);
_cmd.Parameters.AddWithValue("@PhoneWork1", TxtTJob.Text);
_cmd.Parameters.AddWithValue("@Fax", txtOtherN.Text);
_cmd.Parameters.AddWithValue("@Email", Txtemail.Text);
_cmd.Parameters.AddWithValue("@job", Txtjob.Text);
_cmd.Parameters.AddWithValue("@Group1", group1);
_cmd.Parameters.AddWithValue("@Group2", group2);
_cmd.Parameters.AddWithValue("@Group3", group3);
_cmd.Parameters.AddWithValue("@Group4", group4);
_cmd.ExecuteNonQuery();
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}