1

As described in this link , I can create checkbox list in a asp.net webform page .

I want to display each listItem in different Row of html table , As the user will select some files which are being displayed in Different Rows . Each row has a checkbox with it . The user can select multiple files being displayed in multiple Rows .How can I acheive this ?

Here is my code which need to be replaced with asp:Checkbox:

<td valign=bottom align='center'  bgcolor='#DA8191'>
<input type='checkBox' name=chkOnline value='abc'>
<td>

The above code is placed in a loop , so the number of checkbox list items depends upon the file incoming from database .

Thanks in Advance.

2 Answers 2

1

Your question could do with some fleshing out.

As you are using asp.net, I imagine you are also using MVC. so when you say file, i imagine it's whatever your controller is passing to the view. In this case, you must iterate over your model. So, I imagine you need something like:

@model ...

...

@foreach (var s in Model){
<tr>
  <td valign=bottom align='center'  bgcolor='#DA8191'>
    <input type='checkBox' name=chkOnline value='abc'>
  </td>
</tr>
}

...

then you can access any properties on the Model within the for, and thus generate your checkboxes as you wish.

Sign up to request clarification or add additional context in comments.

2 Comments

The fact that he mentions the asp:Checkbox tag and asp.net webform page suggests he's using asp.net web forms.
No , i'm not using MVC
1

You can fill a CheckBoxList from code behind with the values from a database or other source.

<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>

Code behind:

for (int i = 0; i < 5; i++)
{
    CheckBoxList1.Items.Insert(i, new ListItem("Value " + (i + 1), i.ToString(), true));
}

Or with a reader:

int i = 0;
while (reader.Read())
{
    CheckBoxList1.Items.Insert(i, new ListItem(reader["ColumnA"].ToString(), reader["ColumB"].ToString(), true));
    i++;
}

2 Comments

I want to bind each check box at specific <td> under html . How could i do this by using code behind
Then it's easier to use separate CheckBox Controls, not a CheckBoxList.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.