473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

controlling output state of checkbox using ASP.net and SQL server05

hello i just started off with asp.net , needed some help on how to display
the state of checkboxes from a SQL database.

my database table has the following format

seat.dbo ( db design)

( column 1 PK ) id : 1 2 3 4 5 6
(column 2 boolean) state : 1 , 0 , 1 , 0 , 1 , 0

1 stands for checked , 0 uncheck .
i wish to display this checkbox state in 2 rows of 3

o o o
o o o

e.g.

with the code querying the db for the status of the checkboxes before
displaying the output to the user.
if the checkbox 1 , then the user will not be able to uncheck the checkboxes.

( i guess this is more than enough for me , with this example i probably will
be able to figure out how the insert using the checkbox works)

anyone can help ?

Oct 20 '06 #1
1 3092
Please find example below : ( i coded everything in page for clarity, use
code file or
code behind instead )

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
list.DataSource = GetRandomDataSource(10);
list.DataBind();
}
}

private Random random = new Random();
private System.Data.DataTable GetRandomDataSource(int count)
{
if (count < 0)
throw new ArgumentOutOfRangeException();

System.Data.DataTable table = new System.Data.DataTable();
System.Data.DataRow row = null;

table.Columns.Add("Id", typeof(int));
table.Columns.Add("Flag1", typeof(bool));
table.Columns.Add("Flag2", typeof(bool));
table.Columns.Add("Flag3", typeof(bool));

for (int i = 0; i < count; i++)
{
row = table.NewRow();

row[0] = i;
row[1] = this.random.NextDouble() >= 0.5d;
row[2] = this.random.NextDouble() >= 0.5d;
row[3] = this.random.NextDouble() >= 0.5d;

table.Rows.Add(row);
}

return table;
}
protected void list_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gridRow = e.Row;
System.Data.DataRowView dataRow = (System.Data.DataRowView)
gridRow.DataItem;

if (gridRow.RowType == DataControlRowType.DataRow)
{
if ((bool)dataRow["Flag1"])
{
(gridRow.Cells[0].Controls[0] as WebControl).Enabled = true;
(gridRow.Cells[1].Controls[0] as WebControl).Enabled = true;
}
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="list" AutoGenerateColumns="false"
OnRowDataBound="list_RowDataBound">
<Columns>
<asp:CheckBoxField DataField="Flag2"/>
<asp:CheckBoxField DataField="Flag3"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
--
Milosz Skalecki
MCP, MCAD
"aspnoob" wrote:
hello i just started off with asp.net , needed some help on how to display
the state of checkboxes from a SQL database.

my database table has the following format

seat.dbo ( db design)

( column 1 PK ) id : 1 2 3 4 5 6
(column 2 boolean) state : 1 , 0 , 1 , 0 , 1 , 0

1 stands for checked , 0 uncheck .
i wish to display this checkbox state in 2 rows of 3

o o o
o o o

e.g.

with the code querying the db for the status of the checkboxes before
displaying the output to the user.
if the checkbox 1 , then the user will not be able to uncheck the checkboxes.

( i guess this is more than enough for me , with this example i probably will
be able to figure out how the insert using the checkbox works)

anyone can help ?

Oct 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Thomas Lotze | last post by:
Hi, I'm trying to figure out what is the most pythonic way to interact with a generator. The task I'm trying to accomplish is writing a PDF tokenizer, and I want to implement it as a Python...
0
by: Beppe | last post by:
Hi all! I have a .aspx page with 3 hyperlink and 1 checkbox. The NavigateUrl hyperlinks' property retreive dinamically its value (they reload the same page with different params and querystrings);...
1
by: mschoup | last post by:
I have a simple aspx page(WebForm1.aspx) with a HyperLink, LinkButton, and two CheckBoxes. When I select a CheckBox and then click the LinkButton, the CheckBox retains state. When I select the...
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
3
by: 张韡武 | last post by:
Hello. I am a newbie trying to get my first XLST script working. I already know how to do this: Source XML: <category id="a0104"> <name>Oil and Gas</name> </category> XSLT: <xsl:for-each...
3
by: =?Utf-8?B?dmluY2VudHc1Ng==?= | last post by:
I have an ASP.NET 2.0 application. It is pretty basic. What it does is shows a gridview of data from a stored procedure. The user can also select a date filter. The problem is that sometimes an...
2
by: Sideburns | last post by:
I have checkbox's: shop, customer, field, and vendor. When the boxes aren't checked (=false) I would like all the text boxes underneath each check box to be invisible. The textboxes are labeled date...
3
by: Mahathi | last post by:
Hi I have a small problem in maintaining the state of a check box. Please do me a favour by telling me the procedure how to do that. My requirement is that "I have to map some roles with...
10
by: akineko | last post by:
Hi everyone, First of all, I'm not an expert on Javascript. Please forgive me if my question is pointless. I want control a hardware device using a Web browser. I created a page which has a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.