Check box inside repeater , How to get command name value in the check changed function

asp.net, asp.net-4.5

Solution

try this:

Short and simple

Refrence

your check box

<td> 
<asp:CheckBox runat="server" ID="chkStudentStatus"  Text='<%# GetStatusString(Eval("StudentStatus").ToString()) %>' CommandName='<%#Eval("StudentID")%>' OnCheckedChanged="chkStudentStatus_CheckedChanged" Checked='<%#Eval("StudentStatus") %>'  AutoPostBack="True" />
</td>

in code behind

protected void chkStudentStatus_CheckedChanged(object sender, EventArgs e)
{
    var chk = (CheckBox)sender;
    var studentID = chk.Attributes["CommandName"];


}

you can give any named attribute i.e. xyz='<%#Eval("StudentID")%>'

than in code behind

protected void chkStudentStatus_CheckedChanged(object sender, EventArgs e)
{
    var chk = (CheckBox)sender;
    var studentID = chk.Attributes["xyz"];


}

Problem

HI i have above html tag in my asp.net listview item template , ``` <td> <asp:CheckBox runat="server" ID="chkStudentStatus" Text='<%# GetStatusString(Eval("StudentStatus").ToString()) %>' CommandName='<%#Eval("StudentID")%>' OnCheckedChanged="chkStudentStatus_CheckedChanged" Checked='<%#Eval("StudentStatus") %>' AutoPostBack="True" /> </td> ``` While check box value changed i was to get the Command Name value in the " chkStudentStatus_CheckedChanged " function

Original source