I have this code, which is working fine for checkbox, which show records on button click event.
Public Sub ChkFunc()
If chk1.Checked = True Then
ShowData1()
ElseIf chk2.Checked = True Then
ShowData2()
End If
here, ShowData1 And ShowData2 are functions()
And ChkFunc I am calling it on button_click event.
Now what I want is , I want to pass same function as I have passed to Checkbox...to CheckBoxList Control..i.e I want to use CheckBoxList Control instead of individual checkbox
How to do it...?
I hope I am Clear with the query..
Plz Help
Thnx
here, ShowData1 And ShowData2 are functions()
And ChkFunc I am calling it on button_click event.
Now what I want is , I want to pass same function as I have passed to Checkbox...to CheckBoxList Control..i.e I want to use CheckBoxList Control instead of individual checkbox
How to do it...?
I hope I am Clear with the query..
Plz Help
Thnx

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 8:34 PM EDT
Protected Sub Button1_Click(sender As Object, e As EventArgs)
If CheckBoxList1.SelectedIndex = 0 Then
ShowData1()
End If
If CheckBoxList1.SelectedIndex = 1 Then
ShowData2()
End If
If CheckBoxList1.SelectedIndex = 2 Then
ShowData3()
End If
End Sub
Posted Jul 30, 2013, 12:45 PM EDT
Aman Jen136 reputationPosted Jul 30, 2013, 12:51 PM EDT
Based on selection, actually its shows data in gridview from db, So ShowData1 And ShowData2 are functionc , so one or may be both based on selection
Aman Jen136 reputationPosted Jul 30, 2013, 1:54 PM EDT
Trying to bit clear,
I have Multiple Functions to be called using CheckboxList checked item.
Function like:
Item 1 ShowData1()
Item 1 ShowData2()
Item 1 ShowData3()
Item 1 ShowData4()
these functions fetches records from SqlDB and GridView gets populated.
This Stuff is working fine with Individual CheckBox controls ...but unable to do the same thing with CheckBoxList control..
Plz help
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 8:17 PM EDT
Try like this
in your aspx
in your code
..... so on
Let me know if you need any more help
Iftikar
Aman Jen136 reputationPosted Jul 31, 2013, 3:14 AM EDT
here's one issue...If I select multiple options it doesn't show data for selected option all together, both selection function don't execute.
here I have to click button once again to show next item selected...but what i want is it shuld show records for all selected options together..
Thnx Plz help...
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 3:16 AM EDT
Regards,
Iftikar
Aman Jen136 reputationPosted Jul 31, 2013, 3:19 AM EDT
yes I have tried..but
here I have to click button once again to show next item selected...but what i want is it shuld show records for all selected options together..
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 3:34 AM EDT
Protected Sub Button1_Click(sender As Object, e As EventArgs)
For Each listitem As ListItem In CheckBoxList1.Items
If listitem.Selected Then
Dim thisIndex As Integer = CheckBoxList1.Items.IndexOf(listitem)
If thisIndex = 0 Then
ShowData1()
End If
If thisIndex = 1 Then
ShowData2()
End If
End If
Next
End Sub
Aman Jen136 reputationPosted Jul 31, 2013, 4:14 AM EDT
Actually I am fetching data from single table with common index column..@Loan_code...If use
For Each lst As ListItem In chklist.Items
If lst.Selected Then
Dim thisindex As Integer = chklist.Items.IndexOf(lst)
If thisindex = 0 Then
ShowData1()
End If
If thisindex = 1 Then
ShowData2()
End If
If thisindex = 2 Then
ShowData3()
End If
End If
Next
End Sub
It says
The variable name '@Loan_code' has already been declared. Variable names must be unique within a query batch or stored procedure.
ANd if I use this code
'If chklist.SelectedIndex = 0 Then
' ShowData1()
'End If
'If chklist.SelectedIndex = 1 Then
' ShowData2()
'End If
'If chklist.SelectedIndex = 2 Then
' ShowData3()
'End If
as I have said i have to click button for every item selected
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 4:20 AM EDT
Aman Jen136 reputationPosted Jul 31, 2013, 4:24 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 4:33 AM EDT
Public Sub ShowData1(loancode As String)
cmd.Connection = cn
cmd.CommandText = "Select Bor_Name, co_Bor_Name,Intr_Type,Intr_Rest,Curt_ROI,Loan_Sanc,Totl_Loan_Disb,Curt_EMI,Prin_Out From Loan_Acct_Details Where Loan_code=@Loan_code"
cmd.Parameters.AddWithValue("@Loan_code", loancode)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
GDV1.DataSource = ds
GDV1.DataBind()
End Sub
Public Sub ShowData2(loancode As String)
cmd.Connection = cn
cmd.CommandText = "Select Efft_Date,Bank_Fav_Name,chk_Num,co_Bor_Name From Loan_Acct_Details Where Loan_code=@Loan_code"
cmd.Parameters.AddWithValue("@Loan_code", loancode)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
GDV2.DataSource = ds
GDV2.DataBind()
End Sub
Public Sub ShowData3(loancode As String)
cmd.Connection = cn
cmd.CommandText = "Select Intr_Type, Curt_ROI, Loan_Sanc, Prin_Out From Loan_Acct_Details Where Loan_code=@Loan_code"
cmd.Parameters.AddWithValue("@Loan_code", loancode)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
GDV3.DataSource = ds
GDV3.DataBind()
End Sub
Public Sub Chekbox()
For Each lst As ListItem In chklist.Items
If lst.Selected Then
Dim thisindex As Integer = chklist.Items.IndexOf(lst)
If thisindex = 0 Then
ShowData1(lst.Value)
End If
If thisindex = 1 Then
ShowData2(lst.Value)
End If
If thisindex = 2 Then
ShowData3(lst.Value)
End If
End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
cn.Open()
Chekbox()
cn.Close()
End Sub
Aman Jen136 reputationPosted Jul 31, 2013, 5:43 AM EDT
Not workin....and with code given ..is showing one selection at a time on click event....I guess the problem is with For each loop....
Aman Jen136 reputationPosted Jul 31, 2013, 6:06 AM EDT
Dim ckbox As ListItem
Same error with this as well
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 7:10 AM EDT
You are getting this error due to one SqlCommand object For all three method try to use three different sqlcommand object.
i modified your code just check it:
Public Sub ShowData1(loancode As String)
Dim cmd1 As New SqlCommand()
cmd1.Connection = cn
cmd1.CommandText = "Select Bor_Name, co_Bor_Name,Intr_Type,Intr_Rest,Curt_ROI,Loan_Sanc,Totl_Loan_Disb,Curt_EMI,Prin_Out From Loan_Acct_Details Where Loan_code=@Loan_code"
cmd1.Parameters.AddWithValue("@Loan_code", loancode)
Dim da As New SqlDataAdapter(cmd1)
Dim ds As New DataSet()
da.Fill(ds)
GDV1.DataSource = ds
GDV1.DataBind()
End Sub
Public Sub ShowData2(loancode As String)
Dim cmd2 As New SqlCommand()
cmd2.Connection = cn
cmd2.CommandText = "Select Efft_Date,Bank_Fav_Name,chk_Num,co_Bor_Name From Loan_Acct_Details Where Loan_code=@Loan_code"
cmd2.Parameters.AddWithValue("@Loan_code", loancode)
Dim da As New SqlDataAdapter(cmd2)
Dim ds As New DataSet()
da.Fill(ds)
GDV2.DataSource = ds
GDV2.DataBind()
End Sub
Public Sub ShowData3(loancode As String)
Dim cmd3 As New SqlCommand()
cmd3.Connection = cn
cmd3.CommandText = "Select Intr_Type, Curt_ROI, Loan_Sanc, Prin_Out From Loan_Acct_Details Where Loan_code=@Loan_code"
cmd3.Parameters.AddWithValue("@Loan_code", loancode)
Dim da As New SqlDataAdapter(cmd3)
Dim ds As New DataSet()
da.Fill(ds)
GDV3.DataSource = ds
GDV3.DataBind()
End Sub
Public Sub Chekbox()
For Each lst As ListItem In chklist.Items
If lst.Selected Then
Dim thisindex As Integer = chklist.Items.IndexOf(lst)
If thisindex = 0 Then
ShowData1(lst.Value)
End If
If thisindex = 1 Then
ShowData2(lst.Value)
End If
If thisindex = 2 Then
ShowData3(lst.Value)
End If
End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
cn.Open()
Chekbox()
cn.Close()
End Sub
if any problem reply
Aman Jen136 reputationPosted Jul 31, 2013, 7:45 AM EDT
Same Error....:(
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 31, 2013, 7:47 AM EDT
Aman Jen136 reputationPosted Aug 1, 2013, 5:58 AM EDT
Its working as I want but with code created with webservice