Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datalist...I have to bind StudentName with Student Image & also checkbox...now if I select checkbox,I want to get that student Id..how to do this??
please help me out..


[EDIT - OP code from comment]
C#
foreach (DataListItem li in dtlistStudent.Items)
{
    CheckBox chkSelect = (CheckBox)li.FindControl("chkStudent");

    if (chkSelect.Checked == true)
    {
        int result = 0;
        int StudentId = Convert.ToInt32(chkSelect.Checked);
        result = new ClsTransportationStudent
        {
            RouteID = Convert.ToInt32(ddlRoute.SelectedValue),
            PickPointID = Convert.ToInt32(ddlPickPoint.SelectedValue),
            StudentID = Convert.ToInt32(chkSelect.Checked),
        }.Transportation_StudentTransportInsert();


    }
}
Posted
Updated 7-May-14 4:53am
v2
Comments
Rahul Kumar 7-May-14 10:50am    
past some your code
Member 10276220 7-May-14 10:52am    
foreach (DataListItem li in dtlistStudent.Items)
{
CheckBox chkSelect = (CheckBox)li.FindControl("chkStudent");

if (chkSelect.Checked == true)
{
int result = 0;
int StudentId = Convert.ToInt32(chkSelect.Checked);
result = new ClsTransportationStudent
{
RouteID = Convert.ToInt32(ddlRoute.SelectedValue),
PickPointID = Convert.ToInt32(ddlPickPoint.SelectedValue),
StudentID = Convert.ToInt32(chkSelect.Checked),
}.Transportation_StudentTransportInsert();


}
}
Member 10276220 7-May-14 11:02am    
please help me out
Sergey Alexandrovich Kryukov 7-May-14 11:41am    
Please tag your application type. Is it ASP.NET?
If this is a Web application, the hint for you: id is the attribute of HTML element. But what do you have to identify the element if first place? you have to tell us. And why retrieving the id? Maybe the whole idea is wrong? :-)
—SA

1 solution

See article on this topic. Put a hidden field with ID value and get that value on time checkbox click.

ASP.NET - Get selected CheckBox value in DataList[^]
access-hidden-field-at-code-behind.aspx[^]
 
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