Friday, March 25, 2011


This article here decribes the NamingContainer property.

When using a TemplateField in a GridView i.e. when you use... a checkbox to update the database OnCheckChanged of the checkbox

<asp:TemplateField HeaderText="active">
            <asp:CheckBox ID=chkEmpActive AutoPostBack=true Checked='<%#Eval("active")%>' runat=server OnCheckedChanged=chkEmpActive_CheckedChanged />
            <asp:HiddenField ID=hidActive runat=server Value='<%#Eval("emp_id")%>' />

its easier to have a hidden field with it;helps with the update and to find it,  the NamingContainer of the CheckBox can be used to get to the hiddenfield

when you do

protected void checkbox1_oncheckchange(object sender, EventArgs e)
    CheckBoc chk =(CheckBox)sender;
    GridViewRow row = (GridViewRow)chk.NaminConatiner;
    HiddenField hidEmp = (HiddenField)row.FindControl("hidActive");
    empNo = HiddenField.Value; // where empNo is a global var

you can use the empNo variable in JavaScript

var empno = <%=empNo%>

//and use it some calculations


I used the empNo to call an ASP page using the httpXml object and do some database operations

No comments:

Post a Comment