473,756 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp checkbox checking for OnCheckedChange d value

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 checking and unchecking the checkbox
column. I like to update the status in the database for the column where
the status was changed.

This is what I'm doing so far

<asp:datagrid id="MyDataGrid " runat="server" CellPadding="2"
AutoGenerateCol umns="false" HeaderStyle-CssClass="maint ableheader"
Width="95%">
<Columns>
<asp:BoundColum n DataField="BID" ReadOnly="True"
Visible="False" ></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Act ive" Visible="True"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="Status" Runat="server" Checked='<%#
FormatStatus(Da taBinder.Eval(C ontainer.DataIt em, "Status")) %>'
AutoPostBack=Tr ue OnCheckedChange d="UpdateCheckb oxStatus">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
....etc.

and in my .cs page

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
Response.Write ("You click the row...")...
}

How can I find out which row was clicked? Please let me know if there is a
better way to do this.

Thank you
Maz
Nov 18 '05 #1
2 6638
Hi,

you get to the CheckBox's parent DataGridItem by utilizing the hierarchical
idea of Controls collection, meaning that get it via your Control's Parent
property.

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
//Written into several lines to clarify, you could go with one line

//Current checkbox
CheckBox box=(CheckBox)s ender;

//The TableCell the control is in
TableCell cell=(TableCell )box.Parent;

//The DataGridItem the cell belongs to
DataGridItem dgItem=(DataGri dItem)cell.Pare nt;
}

With that DataGridItem you get for example ItemIndex of the DataGridItem you
are into. It is the same would be e.Item in ItemCommand,Ite mDataBound or
ItemCreated. And you can then again get the PK of the current row and so on
via DataKeys collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Maziar Aflatoun" <ma***@rogers.c om> wrote in message
news:27******** *************@n ews01.bloor.is. net.cable.roger s.com...
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 checking and unchecking the checkbox
column. I like to update the status in the database for the column where
the status was changed.

This is what I'm doing so far

<asp:datagrid id="MyDataGrid " runat="server" CellPadding="2"
AutoGenerateCol umns="false" HeaderStyle-CssClass="maint ableheader"
Width="95%">
<Columns>
<asp:BoundColum n DataField="BID" ReadOnly="True"
Visible="False" ></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Act ive" Visible="True"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="Status" Runat="server" Checked='<%#
FormatStatus(Da taBinder.Eval(C ontainer.DataIt em, "Status")) %>'
AutoPostBack=Tr ue OnCheckedChange d="UpdateCheckb oxStatus">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
...etc.

and in my .cs page

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
Response.Write ("You click the row...")...
}

How can I find out which row was clicked? Please let me know if there is a
better way to do this.

Thank you
Maz

Nov 18 '05 #2
Teemu gave a great answer. For some more sample code see my article
here:

http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com

On Sun, 05 Sep 2004 06:12:14 GMT, "Maziar Aflatoun" <ma***@rogers.c om>
wrote:
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 checking and unchecking the checkbox
column. I like to update the status in the database for the column where
the status was changed.

This is what I'm doing so far

<asp:datagri d id="MyDataGrid " runat="server" CellPadding="2"
AutoGenerateCo lumns="false" HeaderStyle-CssClass="maint ableheader"
Width="95%">
<Columns>
<asp:BoundColum n DataField="BID" ReadOnly="True"
Visible="False "></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Act ive" Visible="True"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="Status" Runat="server" Checked='<%#
FormatStatus(D ataBinder.Eval( Container.DataI tem, "Status")) %>'
AutoPostBack=T rue OnCheckedChange d="UpdateCheckb oxStatus">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
...etc.

and in my .cs page

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
Response.Write ("You click the row...")...
}

How can I find out which row was clicked? Please let me know if there is a
better way to do this.

Thank you
Maz


Nov 18 '05 #3

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

Similar topics

6
1601
by: Paul Fitzpatrick | last post by:
Hi, This is a real beginner question! I have a form with a few types of products. I need to limit the number that the user puts in for quantity of each product - I have to keep it below 2. So onsubmit of the form it checks that the values are less than 2. SO far I have -
1
2309
by: Netmonster | last post by:
Hello, Can someone tell me what I'm doing wrong? I am trying to check the value of a hashtable and I know the value will be true or false. The data is coming from a sql db column with bit as its datatype. If the DB value is 0 the hashtable in a vs.net debug shows the value of {false} Here is a piece of code. htData is a return from a sql query. I have tried both
1
2084
by: Paul | last post by:
Hi I have a checkbox which I am disabling in clientside code. On postback, when I try to read the checked value of the disabled checkbox the checkbox property always returns false, even if the checkbox is checked. Surely it should still be true. Any ideas?
2
1773
by: Andy G | last post by:
How can I check this for null? dsPrsn.Tables(0).Rows(0)("WORK_STATE") I tried If IsDbNull(dsPrsn.Tables(0).Rows(0)("WORK_STATE")) Then it seems not too work. I am attempting to check this field in my data set to see if it is null or not. If it is null I want to set my drop down list to a certain value (where I'm using dropdown.SelectedValue = ). If it is not null I want to set the drop down to the dataset value. Here is what the...
0
1353
by: Paul | last post by:
Hello, I have a datagridview with a checkbox in a column, and I want to detect when the user change the value of the checkbox in the event CheckedChanged, but I only detect that the value is changed when the focus is in another column. An idea? Thanks
1
1415
by: Jim in Arizona | last post by:
Using VB .. Is there a way to loop through all drop down lists on a web form checking for a specific value (ddlDropDown.SelectedValue) and then, based on that value, cause a specific label to go visible or not? Thanks, Jim
1
2867
Fary4u
by: Fary4u | last post by:
Hi is any body know where is actual problem is coz it's look me some problem ? to insert value into the MS ACCESS DATABASE after the value is true form html <input type="checkbox" name="1" value="1"> <input type="checkbox" name="2" value="2">
0
779
by: jeenajos | last post by:
Hi all, Im doing a website project.Im stuck in a problem. I have a set of values in database. While entering a value in a textbox it should check whether that value is present in the database or not. and if that value is there, we should check whether its flag value is true or false.If its false we should accept that value from textbox and make the flag as true.If its value is true, we should display an error message. Hw to check whether the...
4
1605
by: F159753 | last post by:
I have the following code: <script type="text/javascript"> function displayRow(){ var ET = document.getElementById("ExpenseTable"); var row3 = document.getElementById("searchbutton"); If row3.value == 'search' { if (row2.value == 'Expenses') {
0
9303
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9541
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8542
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7078
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3651
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 we have to send another system
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.