Click here to Skip to main content
Rate this: bad
good
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 ,..
 
http://www.ezzylearning.com/tutorial.aspx?tid=5187857&q=using-checkbox-in-asp-net-gridview-control
 
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)
            {
                LoadData();
            }
        }
 
        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();
            da.Fill(table);
 
            GridView2.DataSource = table;
            GridView2.DataBind();
            
        }
        
        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;
 

            con.Open();
            com.ExecuteNonQuery();
            con.Close();
 
            LoadData();
            
        }
 
  <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" />
            <Fields>
           
                    
 
                    <asp:TemplateField HeaderText="Confirm Records">
                    <ItemTemplate>
                <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 " %>'  />
                    </ItemTemplate>
                     </asp:TemplateField>
                    
                 <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 3:59am

1 solution

Rate this: bad
good
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:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsviewrow.aspx[^].
 
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.
 
—SA
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 320
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 184
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2014
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