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>
Java
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);
}
}
}
}
Jegadeesh Shanmugavel7 pointsPosted Feb 28, 2017, 7:46 AM EST
What is the issue you are getting. As per my understanding you are always binds the last record for all the row
{ 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); } }