By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

asp:CheckBox problem

P: n/a
Dear All,

First of all, i have a database and i have to select the data in a table.

In the web form, i have a checkbox in each rows. So that the use can select
the row.

initally, i am thinking to use the dataset and databind the datagrid to show
the form.

but i've figured out that, the table style is too complex to use datagrid to
show, thus. i open the HTML code to add
the checkboxs

<%
Dim i As Integer
For i = 0 to 10
%>
<asp:CheckBox id="CheckBox<%=i%>" runat="server"></asp:CheckBox>
<%
Next
%>

i think that i can give a distinct id to each checkbox. e.g.

CheckBox1
CheckBox2
CheckBox3.........

So that i can find out which checkbox has been selected.

But, I have that it is not allowed to use *id="CheckBox<%=i%>"*.

What can i do?

THanks all

Regards,
Casgo
Nov 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
No no no! Use an <asp:checkboxlist> !!

"Harry" <ha******@mail.hongkong.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Dear All,

First of all, i have a database and i have to select the data in a table.

In the web form, i have a checkbox in each rows. So that the use can select
the row.

initally, i am thinking to use the dataset and databind the datagrid to show
the form.

but i've figured out that, the table style is too complex to use datagrid to
show, thus. i open the HTML code to add
the checkboxs

<%
Dim i As Integer
For i = 0 to 10
%>
<asp:CheckBox id="CheckBox<%=i%>" runat="server"></asp:CheckBox>
<%
Next
%>

i think that i can give a distinct id to each checkbox. e.g.

CheckBox1
CheckBox2
CheckBox3.........

So that i can find out which checkbox has been selected.

But, I have that it is not allowed to use *id="CheckBox<%=i%>"*.

What can i do?

THanks all

Regards,
Casgo

Nov 18 '05 #2

P: n/a
i've tried to use it

<asp:checkboxlist id="CheckBoxList1" runat="server">
<% For i = 1 To 10%>
<asp:ListItem></asp:ListItem>
<% Next %>
</asp:checkboxlist>

But error message has been shown

Nov 18 '05 #3

P: n/a
"Harry" <ha******@mail.hongkong.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
i've tried to use it

<asp:checkboxlist id="CheckBoxList1" runat="server">
<% For i = 1 To 10%>
<asp:ListItem></asp:ListItem>
<% Next %>
</asp:checkboxlist>


You must be an old asp programmer :-) as this is how you would do it in asp. asp.net is totally different. You should NEVER put code like that intermixed with the html. Do it from codebehind, or a script block

for i = 1 to 10
CheckBoxList1.items.add(cstr(i))
next

Or even better, if the items you are adding come from a database, you can just bind that to the datasource property of the checkboxlist.

Hope this helps, you should be able to find plenty of help on this out there.
--Michael
Nov 18 '05 #4

P: n/a
Can you look at the following table to see what i am facing? It is quite
difficult to describe here

http://destiny.xfiles.to/ubbthreads/files/543308-2.jpg

-------------------------------------------------------
for i = 1 to 10
CheckBoxList1.items.add(cstr(i))
next
-------------------------------------------------------

if i use this, it is not possible to put each checkbox in a table cell
you can just bind that to the datasource property of the checkboxlist.

for that, i cannot think of any solution to implement the "click and select
all" checkbox
and, it is diffcult to use the default style if i Bind the DataSet in the
DataGrid.
Thank you so much.

"Raterus" <ra*****@spam.org> wrote in message
news:OM*************@tk2msftngp13.phx.gbl...
"Harry" <ha******@mail.hongkong.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... i've tried to use it

<asp:checkboxlist id="CheckBoxList1" runat="server">
<% For i = 1 To 10%>
<asp:ListItem></asp:ListItem>
<% Next %>
</asp:checkboxlist>


You must be an old asp programmer :-) as this is how you would do it in asp.
asp.net is totally different. You should NEVER put code like that
intermixed with the html. Do it from codebehind, or a script block

for i = 1 to 10
CheckBoxList1.items.add(cstr(i))
next

Or even better, if the items you are adding come from a database, you can
just bind that to the datasource property of the checkboxlist.

Hope this helps, you should be able to find plenty of help on this out
there.
--Michael
Nov 18 '05 #5

P: n/a
initially, i think that, directly modify the HTML is the fastest method. as
i don't have to "port" the style from the HTML code to Web Form.
So, i do the old asp method. But latter, i've found that it is not a good
practise in asp.net

I suppose that.............the worst case is

use asp.net as if asp. use <input type='checkbox'.........> instead of
<asp:checkboxlist/>

or

rebuild the table within the codebehind using
"System.Web.UI.WebControls.Table"
both of them are troublesome @@


"Harry" <ha******@mail.hongkong.com> wrote in message
news:ua**************@tk2msftngp13.phx.gbl...
Can you look at the following table to see what i am facing? It is quite
difficult to describe here

http://destiny.xfiles.to/ubbthreads/files/543308-2.jpg

-------------------------------------------------------
for i = 1 to 10
CheckBoxList1.items.add(cstr(i))
next
-------------------------------------------------------

if i use this, it is not possible to put each checkbox in a table cell
you can just bind that to the datasource property of the checkboxlist.

for that, i cannot think of any solution to implement the "click and

select all" checkbox
and, it is diffcult to use the default style if i Bind the DataSet in the
DataGrid.
Thank you so much.

"Raterus" <ra*****@spam.org> wrote in message
news:OM*************@tk2msftngp13.phx.gbl...
"Harry" <ha******@mail.hongkong.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
i've tried to use it

<asp:checkboxlist id="CheckBoxList1" runat="server">
<% For i = 1 To 10%>
<asp:ListItem></asp:ListItem>
<% Next %>
</asp:checkboxlist>

You must be an old asp programmer :-) as this is how you would do it in

asp. asp.net is totally different. You should NEVER put code like that
intermixed with the html. Do it from codebehind, or a script block

for i = 1 to 10
CheckBoxList1.items.add(cstr(i))
next

Or even better, if the items you are adding come from a database, you can
just bind that to the datasource property of the checkboxlist.

Hope this helps, you should be able to find plenty of help on this out
there.
--Michael

Nov 18 '05 #6

P: n/a
Hi, Harr

Datagrid Should be able to do that
1. If checkbox corresponds to a field, then specify a template column containing a checkbox for that
2. Header and footer can be done using Header and FooterTemplat
3. Paging: you can set AllowPaging and PageSize
You might try Repeater too. However, It doesn't provide paging

Bin Song
Nov 18 '05 #7

P: n/a
Thank you for your advice.

By the way, i have another question about paging in Datagrid.

i would like to ask, normal, we bind the datagrid with DataSet

if a query like "select * from item" contains 100000 records, it seems that
getting all the records and load it in the memory(DataSet) is a
resource-consuming task. (please correct me if i say something wrong)

So, i was planning to connect to database and fetch 10 items each time, when
page is changed, connect to database again and fetch next 10 items.

Is my planning a good way to save the resources? or Paging in datagrid has
done something to save the resource?

"Bin Song, MCP" <an*******@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
Hi, Harry

Datagrid Should be able to do that.
1. If checkbox corresponds to a field, then specify a template column containing a checkbox for that. 2. Header and footer can be done using Header and FooterTemplate
3. Paging: you can set AllowPaging and PageSize.
You might try Repeater too. However, It doesn't provide paging.

Bin Song

Nov 18 '05 #8

P: n/a
If you do use a dataset, your next choice is whether you want to recreate it with each round trip. You have two options:

Each time the page is processed, create an instance of the dataset and fill it. When page processing is finished and the page is sent to the browser, the dataset is discarded.
Create and fill the dataset once (typically, the first time the page runs). Then save the dataset in a way that you can retrieve it with each subsequent round trip.
Creating the dataset each time means that with each round trip — effectively, each time the user clicks a button on your page — you execute a query or stored procedure against the data source. For example, you might have a Web Forms page where the user wants to page through data. If you create the dataset each time, the Web Forms page executes a query against the data source to get the next set of records to display

Tip Remember to always minimize data transfer. Whenever practical, use selection criteria to reduce the number of records you need on a page
If you save and restore the dataset, on the other hand, you do not need to go back to the source just to get a few more records. However, saving the dataset has a number of drawbacks. An important one is that the dataset consumes memory between round trips. If the dataset is very large, for example, it can take considerable server memory to store it. If multiple users create large datasets, you can quickly consume available server memory. (An option is to store data in the page; for details, see the next section.)

Another potential drawback is that the dataset can get out of sync with the data source, since you are not refreshing the dataset each time the user clicks a button. If you are working with very volatile data (inventory data, for instance), you might find it better for your application to recreate the dataset with each round trip
Nov 18 '05 #9

P: n/a
got it........thank you so much

"Bin Song, MCP" <an*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
If you do use a dataset, your next choice is whether you want to recreate it with each round trip. You have two options:
Each time the page is processed, create an instance of the dataset and fill it. When page processing is finished and the page is sent to the
browser, the dataset is discarded. Create and fill the dataset once (typically, the first time the page runs). Then save the dataset in a way that you can retrieve it with each
subsequent round trip. Creating the dataset each time means that with each round trip X effectively, each time the user clicks a button on your page X you execute
a query or stored procedure against the data source. For example, you might
have a Web Forms page where the user wants to page through data. If you
create the dataset each time, the Web Forms page executes a query against
the data source to get the next set of records to display.
Tip Remember to always minimize data transfer. Whenever practical, use selection criteria to reduce the number of records you need on a page. If you save and restore the dataset, on the other hand, you do not need to go back to the source just to get a few more records. However, saving the
dataset has a number of drawbacks. An important one is that the dataset
consumes memory between round trips. If the dataset is very large, for
example, it can take considerable server memory to store it. If multiple
users create large datasets, you can quickly consume available server
memory. (An option is to store data in the page; for details, see the next
section.)
Another potential drawback is that the dataset can get out of sync with the data source, since you are not refreshing the dataset each time the user
clicks a button. If you are working with very volatile data (inventory data,
for instance), you might find it better for your application to recreate the
dataset with each round trip.

Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.