[英]unable to bind string values which are separated with comma to a check box list
im editing languages know checkboxes in gridview i have string value english,spanish. 我正在编辑语言,我知道gridview中的复选框,我具有字符串值english,spanish。 while clicking edit button that checkboxlist items should be selected.
在单击“编辑”按钮时,应选中复选框列表项。
i want to get the gridview row column details and want to bind in one checkboxlist. 我想获取gridview行列的详细信息,并希望绑定在一个复选框列表中。 i have binded all languages checkbox .
我已经绑定了所有语言复选框。 i need to to make checkboxes as selected which are already in selected state.
我需要选中已处于选中状态的复选框。
gridview 网格视图
<asp:TemplateField HeaderText="Languages">
<EditItemTemplate>
<asp:TextBox ID="txtLanguages" runat="server" Text='<%# Bind("Languages") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblLanguages" runat="server" Text='<%# Bind("Languages") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
private void bindLanguages()
{
string Languages = "English,Spanish";
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from tbl_Languages";
cmd.Connection = conn;
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
ListItem item = new ListItem();
item.Text = sdr["LanguageName"].ToString();
item.Value = sdr["LanguageId"].ToString();
// item.Selected = Convert.ToBoolean(sdr["IsSelected"]);
chkLanguages.Items.Add(item);
}
}
conn.Close();
}
}
}
public void Bindemployeedetails(string str)
{
DataTable dt = new DataTable();
string Languages = dt.Rows[0]["Languages"].ToString();//English,Hindi
string[] words = Languages.Split(',');
foreach (string word in words)
{
foreach (GridViewRow row in ChkLanguages.Items )
{
if (row.Cells[1].Text == word)
{
CheckBox chkRow = word.ToString();
chkRow.Checked = true;
}
}
}
}
Maybe try with split? 也许尝试拆分?
string[] words = Languages.Split(',');
foreach (string word in words)
{
foreach (GridViewRow row in gdvHealthProblem.Rows)
{
if (row.Cells[1].Text == word)
{
CheckBox chkRow = row.Cells[0].FindControl("chkTableHealthProblem") as CheckBox;
chkRow.Checked = true;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.