
August 24th, 2005, 01:47 AM
|
|
Registered User
|
|
Join Date: Aug 2005
Posts: 2
Time spent in forums: 48 m 43 sec
Reputation Power: 0
|
|
|
retrieving checkbox values in datalist
I have an .aspx page in which I am retrieving categoryid & category name from sql database's category table. Here I am retriving the categoryid value as checkbox value and near by checkbox I am retriving the categoryname for display purpose. What I want is, I have to show what are the categories that I have selected(by checkbox selection) when I am clicking on a button(named as..get items). I am posting the code I am using and attaching the required output.
Code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<HTML>
<HEAD>
<TITLE>UserRegistration-User Details</TITLE>
</HEAD>
<% ' Program for requesting user details %>
<meta content="ASP Express 2.1" name="GENERATOR">
<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
BindData
end if
End Sub
Sub doit(Source as Object, E as EventArgs)
End Sub
Sub BindData()
' To show country table values in list box
'Name of stored proc...>sp_SelectCountry
Dim Varvalu as string
Varvalu="0"
Dim sqls as string = "sp_Selectcategory"
'Connection in web.config file
Dim myConns As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"))
Dim Cmds as New SqlCommand(sqls, MyConns)
Dim objDR as SQLDataReader
cmds.CommandType=CommandType.StoredProcedure ' Tells application that it's using a Stored Procedure
'Dim objDR as SQLDataReader
MyConns.Open()
objDR=Cmds.ExecuteReader(system.data.CommandBehavi or.CloseConnection)
MyDataList.DataSource = objDR
MyDataList.DataBind()
End Sub
</script>
<FORM id="Form1" runat="server">
<asp:datalist id="MyDataList" runat="server" Width="100%" Font-Size="10" GridLines="None" RepeatColumns="2"
Headerstyle-HorizontalAlign="Center" Headerstyle-Font-Size="14" Headerstyle-Font-Bold="True"
Headerstyle-Font-Name="Arial" Headerstyle-BackColor="#E0E0E0" Font-Name="Arial" cellspacing="2"
cellpadding="2">
<ItemTemplate>
<asp:CheckBox ID="CBN1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>' value='<%# DataBinder.Eval(Container.DataItem, "CategoryID") %>'></asp:CheckBox>
<br>
</ItemTemplate>
</asp:datalist>
<asp:Label ID="label1" runat="server" />
<asp:Button id="button1" Text="Get Items" onclick="doit" runat="server" /></FORM>
</HTML>
-------------------
Stored procedure is
Code:
CREATE PROCEDURE sp_SelectCategory
AS
begin
Select Distinct(CategoryName),CategoryID from Category
End
------------------
Category Table is
Code:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_SubCategory_Category]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[SubCategory] DROP CONSTRAINT FK_SubCategory_Category
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Category]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Category]
GO
CREATE TABLE [dbo].[Category] (
[CategoryID] [int] NOT NULL ,
[CategoryName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
-----------------
web.config file is
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyDBConnection" value="server=localhost;uid=sa; pwd=;database=Bids" />
</appSettings>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to insert debugging symbols (.pdb information)
into the compiled page. Because this creates a larger file that executes
more slowly, you should set this value to true only when debugging and to
false at all other times. For more information, refer to the documentation about
debugging ASP.NET files.
-->
<compilation defaultLanguage="vb" debug="true" />
<!-- CUSTOM ERROR MESSAGES
Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
Add <error> tags for each of the errors you want to handle.
"On" Always display custom (friendly) messages.
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not running
on the local Web server. This setting is recommended for security purposes, so
that you do not display application detail information to remote clients.
-->
<customErrors mode="RemoteOnly" />
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are "Windows",
"Forms", "Passport" and "None"
"None" No authentication is performed.
"Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
its settings for the application. Anonymous access must be disabled in IIS.
"Forms" You provide a custom form (Web page) for users to enter their credentials, and then
you authenticate them in your application. A user credential token is stored in a cookie.
"Passport" Authentication is performed via a centralized authentication service provided
by Microsoft that offers a single logon and core profile services for member sites.
-->
<authentication mode="Windows" />
<!-- AUTHORIZATION
This section sets the authorization policies of the application. You can allow or deny access
to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
(unauthenticated) users.
-->
<authorization>
<allow users="*" /> <!-- Allow all users -->
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page within an application.
Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
trace information will be displayed at the bottom of each page. Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web application
root.
-->
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<!-- SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong to a particular session.
If cookies are not available, a session can be tracked by adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>
can anybody help me to solve the problem?
Thanks
Ceema
|