Hi,
I have a question about how I can add and edit a checkbox using the resource LINQ to SQLhttp://www.aspsnippets.com/Articles/LINQ-to-SQL-CRUD-Select-Insert-Edit-Update-and-Delete-using-LINQ-to-SQL-in-ASPNet.aspx for the gridview. could help me how to implement an update for checkbox on gridview? take one of the insert options and became a checkbox but at the time of the update the same decision as if it were a text string instead of a bool. I would like to update as if bool (true, false). It's possible?
here my insert code:
protected void Insert(object sender, EventArgs e)
{
try
{
using (LinqSqlDataContext ctx = new LinqSqlDataContext())
{
T_Accesorio accesorio = (from c in ctx.T_Accesorios
where c.AccesorioName.ToUpper().Trim() == txtAccesorioName.Text.ToUpper().Trim()
orderby c.AccesorioName
select c).FirstOrDefault();
if (accesorio == null)
{
T_Accesorio accesorios = new T_Accesorio
{
AccesorioName = txtAccesorioName.Text.ToUpper().Trim(),
AccesorioStatus = (chkBoxAccesorioStatus.Checked == true) ? "Activo" : "Inactivo"
};
ctx.T_Accesorios.InsertOnSubmit(accesorios);
ctx.SubmitChanges();
}
else
{
}
}
this.BindGrid();
}
catch (Exception ex)
{
Message.Text = "Error: Se Supero el Tiempo de Conexión con la Base de Batos. " + ex.ToString();
}
}
and my update code:
protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow row1 = GridView1.Rows[e.RowIndex];
int AccesorioID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
string AccesorioName = (row1.FindControl("txtAccesorioName") as TextBox).Text;
string AccesorioStatus = (chkBoxAccesorioStatus.Checked == false && true) ? "Activo" : "Inactivo";
using (LinqSqlDataContext ctx = new LinqSqlDataContext())
{
T_Accesorio accesorio = (from c in ctx.T_Accesorios
where c.AccesorioID == AccesorioID
select c).FirstOrDefault();
accesorio.AccesorioName = AccesorioName;
accesorio.AccesorioStatus = AccesorioStatus;
ctx.SubmitChanges();
}
GridView1.EditIndex = -1;
this.BindGrid();
}
catch (Exception ex)
{
throw new Exception("Error Updating the rows. " + ex.Message);
}
}
Please help me out