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

后端 未结 2 398
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 17:11

HI i have above html tag in my asp.net listview item template ,

 


        
相关标签:
2条回答
  • 2021-01-18 18:08
    var item = (RepeaterItem) sender.NamingContainer;
    

    change with:

    var item = (RepeaterItem) chk.NamingContainer;
    
    0 讨论(0)
  • 2021-01-18 18:09

    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"];
    
    
    }
    
    0 讨论(0)
提交回复
热议问题