c# - unable to bind string values which are separated with comma to a check box list -


im editing languages know checkboxes in gridview have string value english,spanish. while clicking edit button checkboxlist items should selected.

i want gridview row column details , want bind in 1 checkboxlist. have binded languages checkbox . need to make checkboxes selected 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 * 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 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") checkbox;                     chkrow.checked = true;                 }             }         } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -