ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModalEditStandType", "$('#myModalEditStandType').modal();", true);
using (con)
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select formid,formName from FormDetails where Edition_Id=" + Session["Edition_ID"].ToString() + " ";
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
chkFormNames.Items.Clear();
while (sdr.Read())
{
ListItem item = new ListItem();
//string StandTypeID =sdr["StandTypeID"].ToString();
item.Text = sdr["formName"].ToString();
item.Value = sdr["FormId"].ToString();
// item.Selected = Convert.ToBoolean(sdr["IsSelected"]);
standName = e.CommandName.ToString();
txtStandType.Text = standName.ToString();
txtStandTypeEdit_ModalBox.Text = standName.ToString();
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
chkFormNames.Items.Add(item);
foreach (var ca in commandArgs)
{
if(ca != null || ca != string.Empty ||ca != "")
{
FormDetails_ID =ca;
if (item.Value == FormDetails_ID)
{
item.Selected = true;
}
}
}
}
}
con.Close();
}
}
grdManageStandType.DataBind();
on the above if condition there is logical error. the issue is in this code only i had debugged the code and checked. let me explain with the example of the error Eg:-
StandTypeName Forms Edit Stand Type
Co-Exhibitor 1, 2, 4 Edit
There are multiple forms. User click on edit button then a modal popup opens and user write the name of StandTypeName and select few checkbox form of multiple ones and then save it. After doing this when User again open modal popup for one of StandTypeName let say here user checks for Co-Exhibitor, there are 3 values given in the Form column for Co-Exhibitor but when user clicks on edit button modal popup opens and only first value is checked the other 2 value is not checked. When i am debugging the code for first form which here is 1 is working fine but for second and third form which here is 2, 4 is giving issue Here
in the below code item.Value == FormDetails_ID is showing true for form 1 when these 2 are equal but for form 2,4 when the item.Value == FormDetails_ID is equal then also item.selected is showing false
if (item.Value == FormDetails_ID)
{
item.Selected = true;
}
at the time of debugging when it checks for Forms 2, the item.value and FormDetails.ID both contains value =2 but doesn't go inside if loop it directly goes out of loop What I have tried but not working:
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModalEditStandType", "$('#myModalEditStandType').modal();", true);
using (con)
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select formid,formName from FormDetails where Edition_Id=" + Session["Edition_ID"].ToString() + " ";
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
ListItem item = new ListItem();
//string StandTypeID =sdr["StandTypeID"].ToString();
item.Text = sdr["formName"].ToString();
item.Value = sdr["FormId"].ToString();
// item.Selected = Convert.ToBoolean(sdr["IsSelected"]);
}
}
con.Close();
}
}
chkFormNames.Items.Clear();
standName = e.CommandName.ToString();
txtStandType.Text = standName.ToString();
txtStandTypeEdit_ModalBox.Text = standName.ToString();
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
chkFormNames.Items.Add(item);
foreach (var ca in commandArgs)
{
if(ca != null || ca != string.Empty ||ca != "")
{
FormDetails_ID =ca;
if (item.Value == FormDetails_ID)
{
item.Selected = true;
}
}
}
grdManageStandType.DataBind();