Hi TPS,
Yes, as Scott has mentioned, you can get the reference to the checkbox in
its postback event and use the Parent property to upper referece its parent
and parent control which is DataGridItem. Here is a simple test page, you
can have a look:
===============aspx================
<HTML>
<HEAD>
<title>CheckGrid</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp
ataGrid id="dgCheck" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Selected">
<ItemTemplate>
<asp:CheckBox ID="chkSelected" Runat="server" AutoPostBack="True"
OnCheckedChanged="chkSelected_CheckedChanged" Checked='<%#
((System.Data.DataRowView)Container.DataItem)["selected"] %>' >
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
</body>
</HTML>
==============code behind========
public class CheckGrid : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgCheck;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Bind_Data();
}
}
protected void Bind_Data()
{
DataTable tb = new DataTable();
tb.Columns.Add("index",typeof(int));
tb.Columns.Add("name",typeof(string));
tb.Columns.Add("selected",typeof(bool));
DataRow row = null;
for(int i=1;i<=15;i++)
{
row = tb.NewRow();
row["index"] = i;
row["name"] = "Name_" + i;
if(i%3==0)
{
row["selected"] = true;
}
else
{
row["selected"] = false;
}
tb.Rows.Add(row);
}
dgCheck.DataSource = tb;
dgCheck.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
protected void chkSelected_CheckedChanged(object sender, System.EventArgs
e)
{
CheckBox chk = (CheckBox)sender;
DataGridItem dgi = (DataGridItem)chk.Parent.Parent;
Response.Write("<br>" + dgi.ItemIndex);
}
}
=============================
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx