checkbox in datagrid

Posted by Sreekanthv5 under WPF on 11/24/2011 | Points: 10 | Views : 4989 | Status : [Member] | Replies : 4
I have a datagrid i have a column isworking. i want to place checkbox in datagrid template. I placed it but its not working. dynamically when i check or uncheck checkbox in datagrid template that row should be hide. where i should write the code what event i have to use. please help me
thank you.
here code.

Collapse | Copy Code

<DataGrid AutoGenerateColumns="False" Name="gv">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Empid}" Header="empid"/>
<DataGridTextColumn Binding="{Binding Path=empname}" Header="ename"/>
<DataGridTextColumn Binding="{Binding Path=deptid}" Header="Age"/>
<DataGridTextColumn Binding="{Binding Path=salary}" Header="Employee Number"/>
<DataGridTextColumn Binding="{Binding Path=joiningdate}" Header="JoiningDate"/>
<DataGridTemplateColumn Header="Isworking">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chk" Content="{Binding Path=isworking}" IsChecked="False" IsThreeState="False"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>




Responses

Posted by: Gsolvers on: 11/24/2011 [Member] Starter | Points: 25

Up
0
Down
Please write the code in iTembound event of the grid....

Best Regards,

VG
www.TeacherJi.com

Sreekanthv5, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: muralikrishnasurap-12704 on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Please check below code ..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataGrid.aspx.cs" Inherits="DataGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="password" HeaderText="Password"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class DataGrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string Connection = "data source=WS-INBLR131\\SQLEXPRESS;initial catalog=Practive;integrated security=true";
SqlConnection _con = new SqlConnection(Connection);
SqlCommand cmd = new SqlCommand("select * from User_details", _con);
cmd.Parameters.AddWithValue("@name", "murali");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
catch (Exception ex)
{
ex.Message.ToString();
}
}

}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
//write code what you want..

}
}




Best Regards
Murali Krishna.S

Sreekanthv5, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sreekanthv5 on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
not in asp.net i am asking in wpf. please see the question and answer me. I have posted in wpf category.

Sreekanthv5, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 7/10/2012 [Member] Starter | Points: 25

Up
0
Down
refer that it may help u

http://www.codeproject.com/Tips/362436/Data-binding-in-WPF-DataGrid-control

Sreekanthv5, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response