10 Answers, 1 is accepted
Try the following code snippet to achieve the desired scenario.
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
if (item.ItemIndex == 0) |
item.Display = false; |
} |
} |
Thanks
Shinu
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
if (item.ItemIndex == 0) { |
item.Display = false; |
break; //terminates the for loop |
} |
} |
I am using a template columnin a radgrid for hiding rows in a radgrid. The column will move the row to another radgrid and after that will hide that row from first grid. I am using "Radgrid1_itemcommand()" method where I am able to hide the row using
if (e.CommandName == "MoveToSelected")
{
// RadGrid1_ItemDeleted(source, e);
GridDataItem dataItem = (GridDataItem)e.Item;
int index = dataItem.ItemIndex;
//e.Item.Visible = false;
foreach (GridDataItem itemm in RadGrid2.MasterTableView.Items)
{
if (itemm.ItemIndex == index)
itemm.Visible =
false;
}
But when I again click on template column to hide another row the first hidden row gets displayed automatically. Basically the grid is allowing us to hide one row at a time. Can any one let me know as to how to hide multiple rows.
Thanks and regards
One option is persisting the hided row by using a Session variable like in this documentation. But instead of persisting the selected row, try the following steps to achieve your requirement.
- Add an ItemCommand event handler to the grid.
- When a "MoveToSelected" command occurs, store the key values for the hided row in a Session variable.
- Add a PreRender event handler to the grid.
- In the pre-render event of the grid, traverse the rows of the grid and compare their key values to the values saved in the Session variable. Whenever you find a match, hide the row.
Thanks,
Princy.
I have been able to resolve my previous problem where only one row was getting hidden at one time, quite a bit.
I have used paging on my grid. The grid shows 5 records on single page. Now when I click, suppose on row 1 of page1, the row1 of page1 gets hidden along with row 1 on all pages. May be this is because all pages maintain row index from 0.
Following is my "OnItemCommand_radgrid_command" method where I maintain all row indexes in session "link" variable.
Then I have implemented "prerender" method where I traverse through "link" variable and one by one hide the rows. But rows from all pages gets hidden.
My "OnItemCommand_radgrid_command" mehtod
protected
void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "MoveToSelected" || e.CommandName == "Delete")
{
// RadGrid1_ItemDeleted(source, e);
GridDataItem dataItem = (GridDataItem)e.Item;
int index = dataItem.ItemIndex;
int[] arrtemp = (int[])Session["hide"];
int iii = (int)Session["var"];
List<int> lint2 = (List<int>)Session["link"];
lint2.Add(index);
Session[
"link"] = lint2;
arrtemp[(
int)Session["var"]] = index;
iii++;
Session[
"var"] = iii;
Session[
"hide"] = arrtemp;
}
And my preprender method
protected void prerender(object sender, System.EventArgs e)
{
int[] arr1 = (int[])Session["hide"];
int val1 = (int)Session["var"];
List<int> lint1 = (List<int>)Session["link"];
if ((bool)Session["state"] == true)
{
Session[
"state"] = false;
}
else
{
foreach (GridDataItem itemm in RadGrid2.MasterTableView.Items)
{
foreach(int oo in lint1)
{
if (itemm.ItemIndex == oo)
itemm.Visible =
false;
}
}
}
}
This is quite problamatic for me.
Kindly let me know as to how to for furthur.
This problem occurs because you have stored the ItemIndex in Session variable. Instead of row index, store the key values for the row in a Session variable as mentioned in the following documentation.
Persisting the selected rows server-side on sorting/paging/filtering/grouping
Hope this helps,
Princy.
Thanks a lot for response
For the time being the problem I am able to get my problem working.
I worked on your suggestion that I was using rowindex in session variable, instead of which i should use key value of rows and I got my problem working.
--------------------------------------------------------------------------------------------------------------------------------------------------
Now I have a asp:panel "panel1" on my .aspx page. This panel is used to contain two radtreeview rtv1 and rtv2, where rtv1 is declared in .aspx page and rtv2 is declared in "page_load event";
There are two asp:radio buttons "rb1" and "rb2". By default "rb1" will get selected and rtv1 will display in panel1.
Now when I click "rb2", rtv1 should get clear from panel1 and rtv2 should get displayed in panel1 i.e. one radtreeview controls should get displayed in panel1 at a time.
I have used session variables to store rtv1, rtv2 , panel1. Now on click of rb2, when I try to remove rtv1 from panel1, it gets removed but after that when I try to add rtv2 to panel1 I get following error
"Script controls may not be registered after PreRender."
I have telerik script manager declared on .aspx page.
Kindly let me know where I am going wrong.
Thanks and Regards
Please take a look at the following code snippet that tried in my application and I hope it will help.
ASPX:
<
asp:RadioButtonList
ID
=
"RadioButtonList1"
runat
=
"server"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"RadioButtonList1_SelectedIndexChanged"
>
<
asp:ListItem
Selected
=
"True"
Value
=
"1"
></
asp:ListItem
>
<
asp:ListItem
Value
=
"2"
></
asp:ListItem
>
</
asp:RadioButtonList
>
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
>
<
telerik:RadTreeView
ID
=
"RadTreeView1"
runat
=
"server"
>
<
Nodes
>
<
telerik:RadTreeNode
Text
=
"Books"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
Text
=
"Paintings"
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeView
>
<
telerik:RadTreeView
ID
=
"RadTreeView2"
runat
=
"server"
Skin
=
"WebBlue"
Visible
=
"false"
>
<
Nodes
>
<
telerik:RadTreeNode
Text
=
"Cars"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
Text
=
"Bike"
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeView
>
</
asp:Panel
>
C#:
protected
void
RadioButtonList1_SelectedIndexChanged(
object
sender, EventArgs e)
{
RadioButtonList radiobtnlist = (RadioButtonList)sender;
Panel panel = (Panel)
this
.FindControl(
"Panel1"
);
RadTreeView treeview1 = (RadTreeView)panel.FindControl(
"RadTreeView1"
);
treeview1.Visible = radiobtnlist.Items[0].Selected;
RadTreeView treeview2 = (RadTreeView)panel.FindControl(
"RadTreeView2"
);
treeview2.Visible = radiobtnlist.Items[1].Selected;
}
Thanks,
Princy.
Thanks again for your reply.
Your last suggentions worked for me quite a bit.
I have implemented your previous reply and it is working fine, just that it postback(whole page gets refreshed) on selecting a radiobutton. SInce both listitem are in same Radiobuttonlist, how can I use the RadioButtonList in telerik:ajaxmanager. Currently I am using
<
telerik:AjaxSetting AjaxControlID="rbl1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadioButtonList1" />
<telerik:AjaxUpdatedControl ControlID="panel1" />
</UpdatedControls
</telerik:AjaxSetting>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
There is yet another issue with my radgrid.
I have a empty "RadGrid1" and hyper links "A","ALL"... on default.aspx page.
On click of "ALL" I have opened a new window pop up using "RadWindow" with radopen = ("default.aspx", radwindowID) method. This will pop up the window on same(default.aspx) page. Now this radwindow is defined on default.aspx page with a another radgrid "radgrid2" in it using content template tags of radwindow. The radgrid2 also has a template column with command = "move to selected" which on click will move the corresponding row from radgrid2 to radgrid1 and hide that row in radgrid2. This process can fill up radgrid1(which was empty). The radgrid2 has "onitemcommand = "radgrid1_itemcommand"" property set to handle click event from template column (command name = "move to selected"), this property has logic for hiding row in radgrid2 and moving row to radgrid1.
Now I have been able to open the window on same page with radgrid2 in it with template column "+" in it.
The page get loads and all GUI gets displayed properly along with radgrid1 and links. WHen I click "ALL" the radwindow gets pop up with data filled radgrid2 with template column "+" in it.
The problem is, when I click "+" i.e. template column for first time the "radgrid1_itemcommand" method does not get fired. But from second click onwards the command gets fired and all workds well (i.e. rows get move to radgrid1 from radgrid2).
On click of template column the radgrid1_itemcommand does not gets fired for first time and because of that, the row does not get move from radgrid2 to radgrid1 only for first time. BUt ll works on and after second click on template column.
PFA the images of my current scenario where "Radgrid_image1" is image where I click on "+" for first time and nothing happens and "radgrid_image2" is image where the row moves to radgrid1 and get hidden in radgrid2.
I have used following telerik:ajaxsetting
<telerik:RadAjaxManager runat="server" ID="radAjax" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid2">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid2"/>
<telerik:AjaxUpdatedControl ControlID="RadGridfirst" />
</UpdatedControls>
</telerik:AjaxSetting>
</telerik:RadAjaxManager>
Important thing that when I comment the above ajax setting code, all start to work well even for firts time i.e. rows gets shifted from from first click on template column. But this process closes the radwindow every time the template column getsclicked, so I have to click "ALL" again for opning the radwindow which is not at all my requirement.
Kindly reply
Thanks and Regards