Custom Datagrid! Help!!!
-
Hi guys, I have two checkboxes on my datagrid and I have an event that fires whenever the first checkbox is checked (code follows)... but I don't know how to figure out where (what index) the checkbox that fired the event is coming from!!! Please Help!!! private void cb_CheckedChanged(object sender, EventArgs e) { bool bIsChecked; CheckBox cbTemp = (CheckBox) sender; bIsChecked = cbTemp.Checked; if (bIsChecked && ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked) ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked = false; } Thanks in advance to anyone who helps me out!
-
Hi guys, I have two checkboxes on my datagrid and I have an event that fires whenever the first checkbox is checked (code follows)... but I don't know how to figure out where (what index) the checkbox that fired the event is coming from!!! Please Help!!! private void cb_CheckedChanged(object sender, EventArgs e) { bool bIsChecked; CheckBox cbTemp = (CheckBox) sender; bIsChecked = cbTemp.Checked; if (bIsChecked && ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked) ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked = false; } Thanks in advance to anyone who helps me out!
hi just lookup this code and try it..
protected void ChkChanged(object s, EventArgs e) { int index = int.Parse(((CheckBox)s).Attributes["myIndex"]); Response.Write(index.ToString()); } private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)e.Item.FindControl("chk"); chk.Attributes.Add("myIndex", e.Item.ItemIndex.ToString()); } }
Mihir... -
hi just lookup this code and try it..
protected void ChkChanged(object s, EventArgs e) { int index = int.Parse(((CheckBox)s).Attributes["myIndex"]); Response.Write(index.ToString()); } private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)e.Item.FindControl("chk"); chk.Attributes.Add("myIndex", e.Item.ItemIndex.ToString()); } }
Mihir... -
hi just lookup this code and try it..
protected void ChkChanged(object s, EventArgs e) { int index = int.Parse(((CheckBox)s).Attributes["myIndex"]); Response.Write(index.ToString()); } private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)e.Item.FindControl("chk"); chk.Attributes.Add("myIndex", e.Item.ItemIndex.ToString()); } }
Mihir... -
When I get to this line, CheckBox chk = (CheckBox)e.Item.FindControl("chk"); I get the error "Object reference not set to an instance of an object" Any ideas of what I may be doing wrong?
hi "myIndex" will be rendered as TAG Attribute like follow ------------------------------------- error you get coz you dont have checkbox in alternative item do one thing, remove e.Item.ItemType == AlternativeItem from if condition hope may be useful to you... Mihir...