asp:CheckBox problem

H

Harry

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
 
H

Harry

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
 
R

Raterus

Harry said:
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
 
H

Harry

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

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.

Harry said:
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
 
H

Harry

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 @@
 
G

Guest

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
 
H

Harry

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 said:
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.
 
G

Guest

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
 
H

Harry

got it........thank you so much

Bin Song said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top