Hi all...
I am not able to form a logic -- Please help --
I have a checklistbox - With a list of names (total 56 names)...
Now, I want that - If I select 5 users , then total 5 records/rows must be saved in the database...
Eg - If I select A,B,C,D,E - Then in database - 5 rows must be inserted in table A with values -
A
B
C
D
E
-----------
How do I form this loop ??
Francis SusaimichaelPosted Feb 3, 2016, 2:20 AM
You need to refer the current item. Not the entire Checkbox List. Try with this code:
private void INsertdata()
{
foreach (ListItem lstItem in chkboxEmpNames.Items
{
if (lstItem.Selected == true)
{
Insert into EmpTable (EmpID) values( convert.toint32(lstItem.Value));
}
}
}
Riddhi ValechaPosted Feb 3, 2016, 1:22 AM
{
chkboxEmpNames.DataSource = Datatable;
chkboxEmpNames.DataTextField = "EmpName";
chkboxEmpNames.DataValueField = "ID";
chkboxEmpNames.DataBind();
}
--
private void INsertdata()
{
foreach (ListItem lstItem in chkboxEmpNames.Items
{
if (lstItem.Selected == true)
{
Insert into EmpTable (EmpID) values( convert.toint32(chkboxEmpNames.SelectedValue));
}
}
}
---------
In "If-Condition" - I get next value , but in "convert.toint32(chkboxEmpNames.SelectedValue)", the value is not moving.
Francis SusaimichaelPosted Feb 2, 2016, 10:50 AM
Have you debugged the application by keeping break points? If possible share your code.
Riddhi ValechaPosted Feb 2, 2016, 8:13 AM
checklistbox1.datavaluefield="ID"
foreach(listitems lst in checklistbox1.items)
{
if(lst.selected == true)
{
// Insert -1
}
}
Likewise, I have selected 1,2,3 values ( DataValueFileds), So I want 3 rows - 1,2,3 in database.
This loop is not iterating on button click event.
Francis SusaimichaelPosted Feb 1, 2016, 9:36 AM
I guess, I have answered your first question. The question you have asked now, is not relevant with your first question. So you need to create a new thread for your question. The reason is if any one refer this thread in future he get confused because of the subject you gave and questions you asked. :)
Riddhi ValechaPosted Feb 1, 2016, 9:27 AM
Francis SusaimichaelPosted Jan 31, 2016, 7:55 PM
foreach(ListItem lstItem in chkBoxList.Items)
{
// check the list item is selected
if(lstItem.Selected)
{
// To do your insert logic here
}
}