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 LenkaPosted Jul 31, 2013, 12:34 AM
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
Aman JenPosted Aug 1, 2013, 9:58 AM
Its working as I want but with code created with webservice
Sanjeeb LenkaPosted Jul 31, 2013, 11:47 AM
Aman JenPosted Jul 31, 2013, 11:45 AM
Same Error....:(
Sanjeeb LenkaPosted Jul 31, 2013, 11:10 AM
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 JenPosted Jul 31, 2013, 10:06 AM
Dim ckbox As ListItem
Same error with this as well
Aman JenPosted Jul 31, 2013, 9:43 AM
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....
Sanjeeb LenkaPosted Jul 31, 2013, 8:33 AM
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 JenPosted Jul 31, 2013, 8:24 AM
Sanjeeb LenkaPosted Jul 31, 2013, 8:20 AM
Aman JenPosted Jul 31, 2013, 8:14 AM
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 LenkaPosted Jul 31, 2013, 7:34 AM
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 JenPosted Jul 31, 2013, 7:19 AM
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..
Iftikar HussainPosted Jul 31, 2013, 7:16 AM
Regards,
Iftikar
Aman JenPosted Jul 31, 2013, 7:14 AM
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 HussainPosted Jul 31, 2013, 12:17 AM
Try like this
in your aspx
in your code
..... so on
Let me know if you need any more help
Iftikar
Aman JenPosted Jul 30, 2013, 5:54 PM
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
Aman JenPosted Jul 30, 2013, 4:51 PM
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
Posted Jul 30, 2013, 4:45 PM