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"
/>