Datagrid problem

R

Raj Anand

I have a dataview and binding to a datagrid. On
ItemBound I'm adding a checkbox dynamically for each
rows. It works ok but my problem is on checkedChanged i
have addded a eventHandler..it's not getting fire at all
In aspx file. Somebody, suggested me to add
<%# chk_Click()%> in my aspx file but it didn't work..Any
help in this regard is appreciated.

Thanks
Raj Anand



=========
ascx.cs file
===========
<asp:datagrid id="DataGrid1" style="Z-INDEX: 103; LEFT:
160px; POSITION: absolute; TOP: 128px" runat="server"
Width="345px" CellPadding="1" BorderColor="Tan"
ForeColor="Black" BackColor="Gainsboro" BorderWidth="1px"
AutoGenerateColumns="False" OnItemDataBound="ItemBound"
OnItemCommand="ItemClick">

<SelectedItemStyle ForeColor="GhostWhite"
BackColor="DarkSlateBlue"></SelectedItemStyle><AlternatingI
temStyle BackColor="White"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True"
BackColor="Tan"></HeaderStyle>
<FooterStyle BackColor="Tan"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="PolicyName" HeaderText="Policy
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="PolicyNumber"
HeaderText="Policy Number"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center"
ForeColor="DarkSlateBlue"
BackColor="PaleGoldenrod"></PagerStyle>
</asp:datagrid>


=========
Code aspx.cs
=========
public void ItemBound(object sender,
DataGridItemEventArgs
e)
{if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView drv = (DataRowView) e.Item.DataItem;
string PolicyName = drv["PolicyName"].ToString();
System.Web.UI.WebControls.CheckBox chk = new CheckBox
(chk.Text = PolicyName;
chk.AutoPostBack = true;
chk.ID = e.Item.ItemIndex.ToString();
e.Item.Cells[0].Controls.Add(chk);
//Add event handler
this.chk.CheckedChanged += new System.EventHandler
(this.chk_Click);

}
}

private void chk_Click(object sender, System.EventArgs e)
{

// Do something
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top