Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Sedlin #1
how to add checkbox to a datagrid?
Hello,
I am trying to add a checkbox to a datagrid. But i dont want to bind a
data with the checkBox. I only want to know if any user has chacked
the checkbox!
How can I do that?
You can try my problem here: :[url]http://das.aspweb.cz/WebForm1.aspx[/url]
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="datagrid.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1"
name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript"
name="vs_defaultClientScript">
<meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX:
101; LEFT: 200px; POSITION: absolute; TOP: 120px"
runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="myItem"
HeaderText="myColumn1"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox
Runat="server" ID="check"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn
Text="Click"></asp:ButtonColumn>
</Columns>
</asp:DataGrid></form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace datagrid
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid
DataGrid1;
protected DataTable dt;
private void Page_Load(object sender, System.EventArgs
e)
{
string[] array = {"Item1", "Item2"};
dt = new DataTable();
dt.Columns.Add("myItem", typeof(string));
for(int i=0; i<20; i++)
dt.Rows.Add(new object[]
{"myLine"+i});
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the
ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_ItemCommand);
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Response.Write(e.Item.Cells[0].Text + ":
checked-");
Response.Write(((CheckBox)e.Item.FindControl("chec k")).Checked.ToString());
}
}
}
Sedlin Guest
-
CheckBox in Datagrid
Hello can anyone help me for displaying a checkbox into datagrid. thanks -
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked.
I am trying to update the database field when the checkbox is clicked. I am trying to modified the following solution but.. got stuck on the... -
CheckBox in DataGrid .
How can I judge which checkbox is checked ? for(int i=0;i<dgOrderList.Items.Count;i++) { CheckBox... -
Added CheckBox to a DataGrid Doesn't work with DataGrid.Enabled=False
I have created a Template Column and Added to a Datagrid, which contains a checkBox. The column is not Binded to any column of the Dataset, but is... -
DataGrid&CheckBox
I have a problem with handle an exception on DataGrid - TemplateColumn I have a datagrid with many columns. One of them is itemID. Second is... -
Elton W #2
how to add checkbox to a datagrid?
You can use
<asp:CheckBox
Runat="server" ID="check" Checked =<%# DataBinder.Eval
(Container.DataItem, "DataFieldName") %> ></asp:CheckBox>
HTH
Elton Wang
[email]elton_wang@hotmail.com[/email]
want to bind a>-----Original Message-----
>Hello,
>I am trying to add a checkbox to a datagrid. But i donthas chacked>data with the checkBox. I only want to know if any userhere: :[url]http://das.aspweb.cz/WebForm1.aspx[/url]>the checkbox!
>
>How can I do that?
>
>You can try my problemTransitional//EN" >>
>
>
><%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>AutoEventWireup="false" Inherits="datagrid.WebForm1" %>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0Studio .NET 7.1"><HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta content="Microsoft Visualrunat="server">>name="GENERATOR">
> <meta content="C#" name="CODE_LANGUAGE">
> <meta content="JavaScript"
>name="vs_defaultClientScript">
> <meta
>content="http://schemas.microsoft.com/intellisense/ie5"
>name="vs_targetSchema">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post"style="Z-INDEX:> <asp:DataGrid id="DataGrid1"DataField="myItem">101; LEFT: 200px; POSITION: absolute; TOP: 120px"
> runat="server"
>AutoGenerateColumns="false">
> <Columns>
> <asp:BoundColumn<asp:TemplateColumn>>HeaderText="myColumn1"></asp:BoundColumn>
><ItemTemplate>><asp:CheckBox></ItemTemplate>>Runat="server" ID="check"></asp:CheckBox>
></asp:TemplateColumn>>System.Web.UI.WebControls.DataGrid> <asp:ButtonColumn
>Text="Click"></asp:ButtonColumn>
> </Columns>
> </asp:DataGrid></form>
> </body>
></HTML>
>
>
>using System;
>using System.Collections;
>using System.ComponentModel;
>using System.Data;
>using System.Drawing;
>using System.Web;
>using System.Web.SessionState;
>using System.Web.UI;
>using System.Web.UI.WebControls;
>using System.Web.UI.HtmlControls;
>using System.Data.SqlClient;
>
>namespace datagrid
>{
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.Page
> {
> protectedSystem.EventArgs>DataGrid1;
> protected DataTable dt;
>
> private void Page_Load(object sender,{"Item1", "Item2"};>e)
> {
>
> string[] array =(string));> dt = new DataTable();
> dt.Columns.Add("myItem", typeofby the> for(int i=0; i<20; i++)
> dt.Rows.Add(new object[]
>{"myLine"+i});
> DataGrid1.DataSource = dt;
> DataGrid1.DataBind();
>
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is requireddo not>ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support -code editor.>modify
> /// the contents of this method with the(this.DataGrid1_ItemCommand);> /// </summary>
> private void InitializeComponent()
> {
> this.DataGrid1.ItemCommand += new
>System.Web.UI.WebControls.DataGridCommandEventHan dlersource,> this.Load += new
>System.EventHandler(this.Page_Load);
>
> }
> #endregion
>
> private void DataGrid1_ItemCommand(object[0].Text + ":>System.Web.UI.WebControls.DataGridCommandEventArg s e)
> {
> Response.Write(e.Item.Cells("check")).Checked.ToString());>checked-");
>
>Response.Write(((CheckBox)e.Item.FindControl> }
> }
>}
>
>.
>Elton W Guest
-
sandy via DotNetMonster.com #3
Re: how to add checkbox to a datagrid?
Check out this site.
[url]http://ww.c-sharpcorner.com/code/2003/june/DatagridAndCheckBoxes.asp[/url]
sandy via DotNetMonster.com Guest



Reply With Quote

