I am using the Infragistics' Ultra webgrid. What i am trying to do is this: my grid has two levels.
i have a checkbox in the header of each level,as well as on every row of the grid
(using cell and header templates). when i check the checkbox located in the header of the second level,
all the rows below the header must get checked i.e. the checkboxes of the rows below the header
should get checked. Please advise. Thanks
Hello,
You can take a look at the following link which provides some information related to your requirements.
http://forums.infragistics.com/forums/p/1540/31497.aspx#31497
Hi Radoslav,
I'd already looked at that page before you replied...:)
Unfortunately, what i'm trying to do is somewhat different. I was wondering if there was anyway
to access a header in the webgrid like any other row is accessed. You knw, something like,
//in the header's checkbox's oncheckedchanged event handler
CheckBox cb = (CheckBox)sender;
HeaderItem hdrItm = cb.Parent;
UltraGridRow row = hdrItm.HeaderRow;
// and then use this row to check or uncheck its children, as and when the header's checkbox is checked
or unchecked.
Thanks anyway.
You are right.
I think that I found a resolution of your issue.
In page_load method
Please see the code in my page_load method:
protected void Page_Load(object sender, EventArgs e)
{
//Bind the grid
if (!IsPostBack) {
UltraWebGrid1.DataSource = MakeTable();
UltraWebGrid1.DataBind();
}
//Find the header check box
TemplatedColumn column = (TemplatedColumn)UltraWebGrid1.Columns[0];
CheckBox headerCheckBox = column.HeaderItem.FindControl("CheckBoxHeader") as CheckBox;
//Attach handler method.
headerCheckBox.CheckedChanged += new EventHandler(headerCheckBox_CheckedChanged);
Then implement headerCheckBox_CheckedChanged like this:
void headerCheckBox_CheckedChanged(object sender, EventArgs e)
CheckBox headerCheckBox = (CheckBox)sender;
if (headerCheckBox.Checked == true)
foreach (CellItem item in column.CellItems)
CheckBox cellCheckBox = item.FindControl("CheckBoxCell") as CheckBox;
cellCheckBox.Checked = true;
else
cellCheckBox.Checked = false;
Please keep in mind that the checkbox in the header is set to AutoPostBack="true"
Let me know your feedback.
Thanks radoslav,
Im almost done. The part where i was getting stuck was getting the templated column...
i was trying to get the row from the checked check box like this...
TemplatedColumn column = (TemplatedColumn)row.Cells.FromKey("chkbx");
If it's not too much (im marking this post as answer..:)) , could you tell me hw this code wud change if
the header was in the second level of the grid, and only its siblings needed to be checked?
Please could you clarify your question below:
Do you mean hierarchical grid with child bands or you just want to know if a checkbox from the given row is checked?
Rishi_Poptani said: if the header was in the second level of the grid, and only its siblings needed to be checked?
if
The answer to both ur questions is yes. I have a hierachical grid with two bands and a
parent child relationship between them i.e. some rows have a (+) next to them, which when
clicked causes the row to expand and reveal its child rows. These child rows, like every row
in the first band of the grid, have a header. This header has a checkbox. On checking/unchecking
this header checkbox, all the rows below only this header must have their checkboxes checked/unchecked.
If I use the code you provided(with a small tweak), all the rows in the child band get their check boxes checked, irrespective
of whether they are siblings or not. Please see if you can work something out.
Thanks,
Rishi
Hi Rishi,
Thanks for the response.
You can distinguish the bands utilizing to the Bands property if we look back at our example :
In order to get the parent band level try this :
first code:
TemplatedColumn column = (TemplatedColumn)UltraWebGrid1].Columns[0];
changed code (it should work ):
TemplatedColumn column = (TemplatedColumn)UltraWebGrid1.Bands[0].Columns[0];
In this way when you iterate over CellItems collection you should check or uncheck only the checkboxes from the parent band. Yo can get a reference to the child band in the same way, just change the Index of the Bands property => Bands[1].
Rishi did you find the solution of this problem ? , i am also stuck in the same situation please help me if you hava a solution.
Rishi Poptani
Did you find the solution?
Trying to solve the same problem.
The best i've found is this post
http://community.infragistics.com/forums/p/6399/27314.aspx
Updated
The proposed in HOWTO solution didn't work, because AfterCellUpdated event doesn't fire.
I've used 2 approaches 1)TemplatedColumn and 2)UltraGridColumn with Type set to CheckBox
In 2) set <input type=checkbox...> as column.HeaderText.(because just setting column type to CheckBox didn't render checkbox in header)
In 1) the template for both header and cell had only checkBox added.
AfterCellUpdated handler wasn't called in 1) and was called in 2) (but only for common cells, not header)
IMPORTANT: Trying to do everything on client side without postback.
Not sure if it could be done on server side, either. The main problem is to get Row/Cell where the clicked checkbox in header is. Solving this problem will get you child rows and you are done.
I am using the code you have provided above i.e.
TemplatedColumn column = (TemplatedColumn)UltraWebGrid1.Bands[0].Columns[0]; //for the
//parent band
TemplatedColumn column = (TemplatedColumn)UltraWebGrid1.Bands[1].Columns[0];
//for the second band
But I think I am not being able to explain the issue to you properly. The thing is, I have two bands
in my grid, but when the checkbox in the header of the second band is clicked, i want ONLY the
rows below the checked header to get checked, not all the grid's rows which happen to lie in the second
band. I hope I am getting through. :)