Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in my checkboxlist there are some classes like 1-b.tech(cse) 2-b.tech(it) 3-b.tech(ece) 4-b.tech(me) when i select b.tech(ece) it give the correct classid of b.tech(ece) and then i select b.tech(me) it give the classid of b.tech(me) again if i select b.tech(it) or b.tech(cse) then it give right classid. basically it pick the first selected classid in cleckbox list. how can i pick the current selected classid on each selection?


1-b.tech(cse) 2-b.tech(it) 3-b.tech(ece) 4-b.tech(me)

i am using this code--

asp.net code-

XML
<td><b>Class:</b></td>
                <td><asp:CheckBoxList ID="CheckBoxList1" runat="server"  AutoPostBack="true"
                RepeatDirection="Horizontal" DataSourceID="SqlDataSource1"
                DataTextField="classes" DataValueField="classesid">
                </asp:CheckBoxList>
                </td>




vb.net code--


VB
Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged

        Dim c As String
        Dim d As String
        Dim f As String


        For i As Integer = 0 To CheckBoxList1.Items.Count - 1

            If CheckBoxList1.Items(i).Selected Then


                cmd.CommandText = "select classes from classes where classesid=" & CheckBoxList1.SelectedValue & ""
                c = cmd.ExecuteScalar

                Label1.Text = c


                cmd.CommandText = "select count(studentid) from stu where classesid=" & CheckBoxList1.SelectedValue & ""
                d = cmd.ExecuteScalar
                Label2.Text = d

                cmd.CommandText = "select count(*) from matrix where classesid=" & CheckBoxList1.SelectedValue & ""
                f = cmd.ExecuteScalar
                Label3.Text = f

                Label4.Text = CInt(Label2.Text) - CInt(Label3.Text)

            Else

            End If
        Next


    End Sub
End Class
Posted

C#
string result = Request.Form["__EVENTTARGET"];
string [] checkedBox = result.Split('$'); ;
int index = int.Parse(checkedBox[checkedBox.Length - 1]);

if (cbYears.Items[index].Selected)
{
  //your logic
}
else
{
  //your logic
}
 
Share this answer
 
C#
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string value = string.Empty;

            string result = Request.Form["__EVENTTARGET"];

            string[] checkedBox = result.Split('$'); ;

            int index = int.Parse(checkedBox[checkedBox.Length - 1]);

            if (CheckBoxList1.Items[index].Selected)
            {
                value = CheckBoxList1.Items[index].Value;
            }

            Response.Write("Last Selected Value : " +  value);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900