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 that of the users of the project. I have used checkboxes for selecting the roles that a particular user has.
For example, an adminstrator has all roles in an organisation. Similarly an Employee has limited roles.
Here let us take administrator and Employee as users. So to assign roles for each of the user I used check boxes. It works fine.
Now my problem is that if at all I require to modify the roles for a particular user as and when I click the users name the chek boxes corresponding to the role names should be checked.
Not only that I also require the code for databinding the control so that if I select a user from the dropdown list for the first time, the options selected for the precious user should be unchecked.
What I mean by this is,
for the first time if I checked a certain roles for the administartor and immediately I selected the user Employee to assign some roles to the employee.
Then all the check boxes should be unchecked.
Hope I explained my problem clearly. If there is any problem in understanding please let me know.
I am sending my code for checkbox checked state and inserting them into the database. I am using oracle database.
And also Iam sending the HTNL.
Protected Sub rpt_ItemDataBou nd(ByVal sender As Object, ByVal e As RepeaterItemEve ntArgs)
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Then
Dim MyCheckBox As CheckBox = CType(e.Item.Fi ndControl("chk" ), CheckBox)
MyCheckBox.Attr ibutes("ROLE_ID ") = e.Item.DataItem ("ROLE_ID").ToS tring()
End If
End Sub
Protected Sub btnUpdate_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnUpdate.Click
Dim rptItem As RepeaterItemCol lection = rpt.Items
Dim cb As CheckBox
con.Open()
Dim cmd As New OracleCommand(" update TSDB_USER_ROLE set IS_DELETED='Y' where USER_ID='" + ddluser.Selecte dValue + "'", con)
cmd.ExecuteNonQ uery()
'con.Close()
For Each item As RepeaterItem In rptItem
cb = CType(item.Find Control("chk"), CheckBox)
If cb.Checked Then
HttpContext.Cur rent.Trace.Writ e("CheckBox Value", cb.Attributes(" ROLE_ID"))
Dim str = cb.Attributes(" ROLE_ID")
'con.Open()
Dim cmd1 As New OracleCommand(" Insert into TSDB_USER_ROLE( USER_ROLE_ID,US ER_ID,ROLE_ID,U PDATEDBY) values(SQDB_USE R_ROLES.nextval ,'" + ddluser.Selecte dValue + "','" + str + "',2)", con)
cmd1.ExecuteNon Query()
End If
Next
con.Close()
End Sub
The above is the code that I used for checking the check boxes and inserting them into the database.
<table id="tbl" width="300" border="1" align="center" cellpadding="1" cellspacing="0" class="greybord er">
<tr>
<td align="center" colspan="2" bgcolor="#ddddd d"><p><strong>U SER ROLES</strong></p></td>
</tr>
<tr>
<td style="width: 80px"><p>User Name</p></td>
<td><p><asp:Dro pDownList ID="ddluser" runat="server" AutoPostBack="t rue" DataSourceID="S qlDataSource1" DataTextField=" LOGIN_NAME" DataValueField= "USER_ID"></asp:DropDownLis t><asp:SqlDataS ource ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:SUPPLIERDB %>"
ProviderName="< %$ ConnectionStrin gs:SUPPLIERDB.P roviderName %>" SelectCommand=' SELECT "USER_ID", "LOGIN_NAME " FROM "TSDB_USERMASTE R"'>
</asp:SqlDataSour ce>
</p></td>
</tr>
<tr>
<td align="center" colspan="2"><p> <strong>ROLES </strong></p></td>
</tr>
<tr>
<td>
<asp:Repeater ID="rpt" runat="server" DataSourceID="S qlDataSource3" OnItemDataBound ="rpt_ItemDataB ound">
<ItemTemplate >
<tr>
<td align="center"> <p><%#Container .DataItem("ROLE _NAME") %></p></td>
<td align="center"> <asp:CheckBox ID="chk" runat="server" AutoPostBack="t rue" />
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSou rce ID="SqlDataSour ce3" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:SUPPLIERDB %>"
ProviderName="< %$ ConnectionStrin gs:SUPPLIERDB.P roviderName %>" SelectCommand=' SELECT "ROLE_ID","ROLE _NAME" FROM "TSDB_ROLES "'>
</asp:SqlDataSour ce>
</td>
This is the HTML that I have used. I googled it out for two days. Even then there is no progress. So I am using this form.
Please help me in doing the work.
Thanks in advance for any help provided.
Regards,
Mahathi.
3 2908
Have you tried setting viewstate to true?
Hi
Thank you for the immediate reply.
Where should I set the View State property to true?
Regards
Mahathi.
Hi
I could get the values of the check boxes that are inserted in the database using a datareader.
The code used by me is as follows:
Dim cmd As New OracleCommand(" Select USER_ID,ROLE_ID from TSDB_USER_ROLE where USER_ID='" + ddluser.Selecte dValue + "' and IS_DELETED='N'" , con)
Dim dr As OracleDataReade r = cmd.ExecuteRead er()
While dr.Read
Dim str = dr.Item("ROLE_I D").ToString ()
Response.Write( str)
End While
Now please let me know based on these values how to make the checkboxes checked for a particular user in the form. That is the checkboxes that are checked should only be checked.
Thanks in advance for any help provided.
Regards
Mahathi.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Thomas R |
last post by:
Is is possible?
In VS.NET 2003, Binding data to the repeater is easy, but when I try to add
an ASP:checkbox to the .aspx page, the designer won't recognize it, hence
the code view doesn't allow me to access it. The funny thing is that it
compiles fine, and the checkboxes are there, I just can't write to them!
Is there a way around this problem?
My HTML is as follows:
|
by: Mark |
last post by:
I am attempting to build a repeating list using a repeater control. I want
to add a checkbox to each item (line) and 'Select All' and 'Clear All'
buttons.
I have figured out how to do this until it comes time to implement paging.
Without paging I can iterate through the repeater when I click 'Select All'
and set the checked property to true for all items in the repeater.
However when I implement paging, I have to rebind the repeater...
|
by: Jack Turnbull |
last post by:
Hi,
I have a Checkbox in a Repeater set to AutoPostBack = true. I have pointed
OnCheckedChanged to a Sub but it doesn't fire. If I move the checkbox out of
the Repeater it fires! Any ideas?
Thanks
|
by: Leo J. Hart IV |
last post by:
Hello,
I'm hoping someone can help me out.
I was wondering if the Enabled property of a CheckBox or RadioButton
server control is stored in the ViewState. If not, is there some way
to to add this property to ViewState? If needed, I can give you more
info on exactly what I'm trying to do.
Thanks,
|
by: Andrew |
last post by:
Hi,
I have a problem capturing the checkboxes that are checked, I get false
irrespective of wether they are checked or not.
I have gone thru the sample code on this forum, but they dun seem to work.
This is the code that I used to go thru the repeater control to find my
checkboxes.
foreach(RepeaterItem r in MyRepeater.Items)
| |
by: Alan Silver |
last post by:
Hello,
I have a repeater that has code like this...
<ItemTemplate>
<asp:CheckBox ID="chkDelete" Text="" RunAt="server"/>
.... other stuff goes here
</ItemTemplate>
There is a button below the repeater. When clicked, it is supposed to
|
by: Keith |
last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate.
Each item contains a checkbox with an ID of chkReconciled, and the header
contains a single checkbox with an ID of chkAll. I simply want to have
chkAll be checked if every item in the repeater has its checkbox checked. In
the code behind page, I can access the checked property of chkReconciled by
doing the following:
Dim CurrentCheckBox As CheckBox...
|
by: deathtospam |
last post by:
A few weeks ago, I created a Classic ASP page that connects to a
machine with SQL Server installed on it, prompts the user to select a
database on that server, then lists all of user-created stored
procedures in that database. The user can select any of those stored
procedures by clicking on checkboxes; after submitting their
selections, a script to delete and then re-create each stored procedure
will be generated. Now I'm trying to do...
|
by: LionsDome |
last post by:
Hello,
I have a vb.net page which a bunch of checkboxes. A user can select a
checkbox(s) and hit the submit button to store those values in a SQL
Server table. This works fine with no problem the first time the user
submits. However when user submits a second time while changing some
of the selected boxes the page only re-submits the previosly selected
checkbox values. It's like its storing it somewhere in the cache or
something. My...
|
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...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |