Click here to Skip to main content
13,048,035 members (115,611 online)
Rate this:
Please Sign up or sign in to vote.
i want a check box in detaill view for approved and not approved with Sql Server if i checked checkbox it should save in data base as approved or true ,

this link work fine for me for gridview i want it in DetailView ,..

here is my code i am getting error on "Cells"

Error 18 'System.Web.UI.WebControls.DetailsView' does not contain a definition for 'Cells' and no extension method 'Cells' accepting a first argument of type 'System.Web.UI.WebControls.DetailsView' could be found (are you missing a using directive or an assembly reference?) C:\Users\Administrator\Documents\Visual Studio 2010\KSMC_EmpDtl\KSMC_EmpDtl\search.aspx.cs 50 30 KSMC_EmpDtl

 protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
        private void LoadData()
            string query = @"SELECT ID,Name,Emp_No,Job_Title,Nationality,Administration,Section,Another_job,health_no,Exp_Date,National_ID,serial_no,reference,confirm_rcrd,arabic_name,arabic_jobtitle FROM KSMCemp_data";
            SqlDataAdapter da = new SqlDataAdapter(query, con);
            DataTable table = new DataTable();
            GridView2.DataSource = table;
        public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
            CheckBox chkStatus = (CheckBox)sender;
            DetailsView row = (DetailsView)chkStatus.NamingContainer;

            string cid = row.Cells[1].Text;                              <<--- ERROR 
            bool status = chkStatus.Checked;

            string query = "UPDATE KSMCemp_data SET confirm_rcrd = @confirm_rcrd WHERE ID = @ID";
            SqlCommand com = new SqlCommand(query, con);

            com.Parameters.Add("@confirm_rcrd", SqlDbType.Bit).Value = status;
            com.Parameters.Add("@ID", SqlDbType.Int).Value = cid;


  <asp:DetailsView ID="DetailsView1" runat="server"  
            AutoGenerateRows="False" CellPadding="4"  DataKeyNames="ID"
            ForeColor="#333333" GridLines="Horizontal" Height="50px" 
            Width="291px" HorizontalAlign="Left" ViewStateMode="Enabled">
            <AlternatingRowStyle BackColor="White" />
            <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
            <EditRowStyle BackColor="#2461BF" />
            <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
                    <asp:TemplateField HeaderText="Confirm Records">
                <asp:CheckBox ID="chkStatus" runat="server" 
                            AutoPostBack="true" OnCheckedChanged="chkStatus_OnCheckedChanged"
                            Checked='<%# Convert.ToBoolean(Eval("confirm_rcrd")) %>'
                            Text='<%# Eval("confirm_rcrd").ToString().Equals("True") ? " Confirm " : " Pending " %>'  />
                 <asp:BoundField DataField="ID" HeaderText="Serial No" />
                <asp:BoundField DataField="Name" HeaderText="Name"  />
                <asp:BoundField DataField="Emp_No" HeaderText="Emp_No" 
Posted 21-Oct-12 2:59am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Isn't the error message quite obvious? There is no such member as Cells in the class System.Web.UI.WebControls.DetailsView.

Your variable naming (row) creates the impression that you somehow mixed up two different classes: System.Web.UI.WebControls.DetailsView and, probably, System.Web.UI.WebControls.DetailsViewRow, which does have the property Cells. Please see:[^],[^].

Even if you correctly calculated the row reference in the preceding line of code (so the typecast won't throw invalid cast exception), this variable will get a reference to some System.Web.UI.WebControls.DetailsViewRow instance which you can use to reference on of the particular row instances; please see the first MSDN article referenced above.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100