Hassan Alhag

Hassan Alhag

  • NA
  • 30
  • 1.2k

Comma delimited string to chkbList in gridview from databse?

Feb 25 2017 1:47 AM

Hi, All,

I have a problem to populate a comma delimited string from the database stored in Arabic like this (????? ????,???? ????? ?????,???? ???? ?????,???? ?????,) to a checkboxlist inside a gridview edit template?

 
here what my Code Look like:
 
<Columns>
<asp:BoundField DataField="TransactionName" HeaderText="Transaction Name" />
<asp:BoundField DataField="Category" HeaderText="Category" />
<asp:TemplateField HeaderText="Steps">
<ItemTemplate>
<asp:Label ID="lblBrand" runat="server" Text='<%#Eval("Steps") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
 
 
string checkBoxValues = "";
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBoxList chkBrand = (CheckBoxList) e.Row.FindControl("CheckBoxList1");
String SQL = "SELECT * FROM TransactionDetail";
string sConstr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(sConstr))
{
using (SqlCommand comm = new SqlCommand(SQL, conn))
{
conn.Open();
SqlDataReader myReader = null;
myReader = comm.ExecuteReader();
while (myReader.Read())
{
checkBoxValues = (myReader["Steps"].ToString());
}
foreach (string value in checkBoxValues.Split(','))
{
ListItem item = new ListItem();
item.Text = value;
item.Value = value;
chkBrand.Items.Add(item);
}
}
}
}
 

Answers (1)