CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2342|Reply: 2

Populate gridview from checkboxlist

[Copy link]
Post time 29-4-2009 01:43 PM | Show all posts |Read mode
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..

Reply

Use magic Report


ADVERTISEMENT


 Author| Post time 29-4-2009 01:43 PM | Show all posts
.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 &amp; Innovation</aspistItem>

<aspistItem Value="2">Leadership &amp; Intellectual</aspistItem>

<aspistItem Value="3">Social &amp; Community Service</aspistItem>

<aspistItem Value="4">Spiritual</aspistItem>

<aspistItem Value="5">Sports, Culture &amp; Recreation</aspistItem>

</aspheckBoxList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStringsonnectionString %>"

SelectCommand="SELECT [ScorunCategoryID], [Description] FROM [ScorunCategory]"></asp:SqlDataSource>

&nbsp;<br />

<br />

&nbsp;<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', &#13;&#10;oz.name as Organizer, l.Name AS 'Officer-In-Charge', a.Capacity, &#13;&#10;a.RegistrationStartDate,a.RegistrationEndDate, al.Description AS Location, &#13;&#10;a.StartDate, a.EndDate, l.HandPhone,a.Fee, rt.Description AS 'Registration Type', &#13;&#10;a.Note, a.Synopsis,isnull(a.verifierid,0) as verifierid ,&#13;&#10;isnull(a.verifydate,'') as verifydate,sa.description as category FROM Activity a &#13;&#10;join scorunactivitycategory sac on sac.activityid = a.activityid&#13;&#10;join scoruncategory sa on sa.scoruncategoryid = sac.scoruncategoryid&#13;&#10;LEFT OUTER JOIN ActivityLocation al ON a.ActivityLocationID = al.ActivityLocationID &#13;&#10;LEFT OUTER JOIN RegistrationType rt ON a.RegistrationTypeID = rt.RegistrationTypeID &#13;&#10;LEFT OUTER JOIN ScorunType st ON a.ScorunTypeID = st.ScorunTypeID &#13;&#10;LEFT OUTER JOIN ScorunZone sz ON a.ScorunZoneID = sz.ScorunZoneID &#13;&#10;LEFT OUTER JOIN Lecturer l ON a.OfficerID = l.LecturerID&#13;&#10;LEFT OUTER JOIN organizer oz ON oz.Organizerid=a.organizerid &#13;&#10;where verifierid is not null&#13;&#10;and sa.scoruncategoryid in (1,2,3,4,5)&#13;&#10;ORDER BY a.ActivityID DESC">

</asp:SqlDataSource>

<br />

<br />

&nbsp;<br />

&nbsp;


</aspontent>
Reply

Use magic Report

 Author| Post time 29-4-2009 01:43 PM | Show all posts
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
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

24-1-2025 10:33 PM GMT+8 , Processed in 0.471892 second(s), 16 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list