View: 2342|Reply: 2
|
Populate gridview from checkboxlist
[Copy link]
|
|
salam..
aku ada masalah dalam asp.net...
camne aku nak populate gridview drpd multiple checkbox list..cthnye aku select 2-3 item dari checkboxlist aku pastu aku kuar data dalam gridview based on ape yang aku select tu..ni coding untuk checkbox aku..
|
|
|
|
|
|
|
|
.aspx
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ListofCategory.aspx.vb" Inherits="ListofCategory" title="List of Category" %>
<aspontent ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<strong>List of Category :<br />
</strong>
<br />
<aspheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Description" DataValueField="ScorunCategoryID">
<aspistItem Value="1">Enterpreneurship & Innovation</aspistItem>
<aspistItem Value="2">Leadership & Intellectual</aspistItem>
<aspistItem Value="3">Social & Community Service</aspistItem>
<aspistItem Value="4">Spiritual</aspistItem>
<aspistItem Value="5">Sports, Culture & Recreation</aspistItem>
</aspheckBoxList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStringsonnectionString %>"
SelectCommand="SELECT [ScorunCategoryID], [Description] FROM [ScorunCategory]"></asp:SqlDataSource>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="ActivityID">
<Columns>
<asp:BoundField DataField="scoruncategoryid" HeaderText="scoruncategoryid" InsertVisible="False"
ReadOnly="True" SortExpression="scoruncategoryid" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
<asp:BoundField DataField="ActivityID" HeaderText="ActivityID" InsertVisible="False"
ReadOnly="True" SortExpression="ActivityID" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Zone" HeaderText="Zone" SortExpression="Zone" />
<asp:BoundField DataField="Activity Type" HeaderText="Activity Type" SortExpression="Activity Type" />
<asp:BoundField DataField="Organizer" HeaderText="Organizer" SortExpression="Organizer" />
<asp:BoundField DataField="Officer-In-Charge" HeaderText="Officer-In-Charge" SortExpression="Officer-In-Charge" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity" SortExpression="Capacity" />
<asp:BoundField DataField="RegistrationStartDate" HeaderText="RegistrationStartDate"
SortExpression="RegistrationStartDate" />
<asp:BoundField DataField="RegistrationEndDate" HeaderText="RegistrationEndDate"
SortExpression="RegistrationEndDate" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:BoundField DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" />
<asp:BoundField DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" />
<asp:BoundField DataField="HandPhone" HeaderText="HandPhone" SortExpression="HandPhone" />
<asp:BoundField DataField="Fee" HeaderText="Fee" SortExpression="Fee" />
<asp:BoundField DataField="Registration Type" HeaderText="Registration Type" SortExpression="Registration Type" />
<asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note" />
<asp:BoundField DataField="Synopsis" HeaderText="Synopsis" SortExpression="Synopsis" />
<asp:BoundField DataField="verifierid" HeaderText="verifierid" ReadOnly="True" SortExpression="verifierid" />
<asp:BoundField DataField="verifydate" HeaderText="verifydate" ReadOnly="True" SortExpression="verifydate" />
<asp:BoundField DataField="category" HeaderText="category" SortExpression="category" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStringsonnectionString %>"
SelectCommand="SELECT sa.scoruncategoryid,a.Date, a.ActivityID, a.Description,sz.Description AS Zone, st.Code AS 'Activity Type', oz.name as Organizer, l.Name AS 'Officer-In-Charge', a.Capacity, a.RegistrationStartDate,a.RegistrationEndDate, al.Description AS Location, a.StartDate, a.EndDate, l.HandPhone,a.Fee, rt.Description AS 'Registration Type', a.Note, a.Synopsis,isnull(a.verifierid,0) as verifierid , isnull(a.verifydate,'') as verifydate,sa.description as category FROM Activity a join scorunactivitycategory sac on sac.activityid = a.activityid join scoruncategory sa on sa.scoruncategoryid = sac.scoruncategoryid LEFT OUTER JOIN ActivityLocation al ON a.ActivityLocationID = al.ActivityLocationID LEFT OUTER JOIN RegistrationType rt ON a.RegistrationTypeID = rt.RegistrationTypeID LEFT OUTER JOIN ScorunType st ON a.ScorunTypeID = st.ScorunTypeID LEFT OUTER JOIN ScorunZone sz ON a.ScorunZoneID = sz.ScorunZoneID LEFT OUTER JOIN Lecturer l ON a.OfficerID = l.LecturerID LEFT OUTER JOIN organizer oz ON oz.Organizerid=a.organizerid where verifierid is not null and sa.scoruncategoryid in (1,2,3,4,5) ORDER BY a.ActivityID DESC">
</asp:SqlDataSource>
<br />
<br />
<br />
</aspontent> |
|
|
|
|
|
|
|
Imports System.Data
Imports System.Data.SqlClient
Partial Class ListofCategory
Inherits System.Web.UI.Page
Dim conn As New SqlConnection
Dim com As New SqlCommand
Dim dr As SqlDataReader
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim description As Boolean = False
' Iterate through the Products.Rows property
For Each row As GridViewRow In GridView1.Rows
' Access the CheckBox
Dim cb As CheckBox = row.FindControl("CheckBox1")
Dim activityid As Integer = _
Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value)
'If cb IsNot Nothing AndAlso cb.Checked Then
'
com.CommandText = "SELECT sa.scoruncategoryid,a.Date, a.ActivityID, a.Description,sz.Description AS Zone, st.Code AS 'Activity Type', " _
& "oz.name as Organizer, l.Name AS 'Officer-In-Charge', a.Capacity, " _
& " a.RegistrationStartDate,a.RegistrationEndDate, al.Description AS Location, " _
& "a.StartDate, a.EndDate, l.HandPhone,a.Fee, rt.Description AS 'Registration Type'," _
& "a.Note, a.Synopsis,isnull(a.verifierid,0) as verifierid ," _
& "isnull(a.verifydate,'') as verifydate,sa.description as category FROM Activity a " _
& "join scorunactivitycategory sac on sac.activityid = a.activityid " _
& "join scoruncategory sa on sa.scoruncategoryid = sac.scoruncategoryid" _
& "LEFT OUTER JOIN ActivityLocation al ON a.ActivityLocationID = al.ActivityLocationID " _
& "LEFT OUTER JOIN RegistrationType rt ON a.RegistrationTypeID = rt.RegistrationTypeID " _
& "LEFT OUTER JOIN ScorunType st ON a.ScorunTypeID = st.ScorunTypeID " _
& "LEFT OUTER JOIN ScorunZone sz ON a.ScorunZoneID = sz.ScorunZoneID " _
& "LEFT OUTER JOIN Lecturer l ON a.OfficerID = l.LecturerID" _
& "LEFT OUTER JOIN organizer oz ON oz.Organizerid=a.organizerid " _
& "where(verifierid Is Not null)" _
& "and sa.scoruncategoryid=@scoruncategoryid" _
& "ORDER BY a.ActivityID DESC"
'Dim arr() As String = list.ToArray(GetType(String))
'Dim test_item As String = String.Join(",", arr)
' First, get the visible for the selected row
com.Connection = conn
com.ExecuteNonQuery()
Next
'Else
' com.CommandText = "update apartmentbed set visible=1 where abid=" & abid & ""
'com.Connection = conn
'com.ExecuteNonQuery()
'GridView1.Visible = True
End Sub
End Class |
|
|
|
|
|
|
| |
|