473,465 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

asp:CheckBox problem

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
9 2280
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
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
"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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Maziar Aflatoun | last post by:
Hi everyone, I am reading and displaying data rows from my database where the first column contains the Status checkbox. I like to enable my users to change the status of individual rows by...
3
by: C | last post by:
Hi, I have an asp server side checkbox as below. I have a page where users can edit their user record. I set this checkbox to true based on a value in a database. <asp:checkbox...
2
by: Maziar Aflatoun | last post by:
Hi everyone, I am reading and displaying data rows from my database where the first column contains the Status checkbox. I like to enable my users to change the status of individual rows by...
3
by: Jim Bancroft | last post by:
Hi everyone, This is a silly one I'm sure, but I'm having a whale of a time putting some text into my asp checkbox. Here's what I'd like to do: <asp:CheckBox runat="server"...
2
by: UJ | last post by:
Is there a way with a asp:checkbox to run a JavaScript to display/hide text/input on the screen without doing a postback? I also need to be able to access the stuff at the server so I need to...
1
by: UJ | last post by:
I have a table that I need to manually generate based on stuff in the database. I build the actual table string and stuff it into an asp:panel. So far it works fine. I'm now trying to add a...
1
by: Phils | last post by:
I have a simple problem but after an afternoon of searching still cant get a solution. I have an asp checkbox on my form that i want to, when checked, enable a textbox. when the checkbox is...
4
by: Mike Haberfellner | last post by:
....hi everyone, ....i posted this allready, but my newsreader doesn't display it to me - so i'm sorry if it's posted twice... hi again, sorry for not clearly writing what i really need :) ...
1
by: mark4asp | last post by:
Here is the control: <asp:CheckBox ID="chkLite" runat="server" Checked="False" AutoPostBack="True" OnCheckedChanged="chkLite_CheckedChanged" /> Here is the code-behind: ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.