Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 468
Vinoth Avatar asked Aug 26 '13 07:08

Vinoth


1 Answers

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"];


}
like image 181
sangram parmar Avatar answered Oct 19 '22 23:10

sangram parmar