Eric Skaggs
Top achievements
Rank 2
Eric Skaggs
asked on 27 Aug 2009, 10:17 AM
Hello,
In my grid's edit form template, I have an asp:Panel control that has the "Visible=false" attribute. I only want to show that section of the edit form template in certain cases. It should not be displayed for every item that is in edit mode.
I'm having trouble programmatically getting a reference to my panel. I've tried accessing it in the ItemCommand and PreRender events for the RadGrid, but every time I cannot obtain a reference to an instance of that object.
Can anyone give me a general idea of what method/event I should be attempting to do this from? Does it sound like I'm doing something wrong?
Thank you,
Eric Skaggs
In my grid's edit form template, I have an asp:Panel control that has the "Visible=false" attribute. I only want to show that section of the edit form template in certain cases. It should not be displayed for every item that is in edit mode.
I'm having trouble programmatically getting a reference to my panel. I've tried accessing it in the ItemCommand and PreRender events for the RadGrid, but every time I cannot obtain a reference to an instance of that object.
Can anyone give me a general idea of what method/event I should be attempting to do this from? Does it sound like I'm doing something wrong?
Thank you,
Eric Skaggs
4 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Aug 2009, 05:27 AM
Hi Eric,
Try the following code snippet for show/hide the panel in FormTemplate based on condition (here value in the row).
CS:
-Shinu.
Try the following code snippet for show/hide the panel in FormTemplate based on condition (here value in the row).
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditFormItem && e.Item.IsInEditMode) |
{ |
GridEditFormItem editItem = (GridEditFormItem) e.Item; |
if (editItem["CustomerID"].Text == "ALFKI") // Check for condition |
{ |
GridEditFormItem item = (GridEditFormItem)e.Item; |
Panel panel1 = (Panel)item.FindControl("Panel1"); |
panel1.Visible = false; |
} |
} |
} |
-Shinu.
0
Jacob Button
Top achievements
Rank 1
answered on 10 Sep 2009, 03:35 PM
How would I go about achieving this functionality if my form template is not autogenerated?
I'm getting this error message.
I'm getting this error message.
Item in insert mode does implement indexer only when the edit form is autogenerated |
0
Princy
Top achievements
Rank 2
answered on 11 Sep 2009, 06:05 AM
Hi Jacob,
Here is a sample code to access the FormTemplate controls when in insert mode and edit mode. If this does not help consider sending your aspx code.
ASPX:
CS:
Thanks
Princy
Here is a sample code to access the FormTemplate controls when in insert mode and edit mode. If this does not help consider sending your aspx code.
ASPX:
<EditFormSettings EditFormType="Template"> |
<FormTemplate> |
<asp:Panel ID="Panel1" runat="server"> |
'Hello' |
</asp:Panel> |
</FormTemplate> |
</EditFormSettings> |
CS:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) |
{ |
GridEditFormItem editformItem = (GridEditFormItem)e.Item; |
Panel panel1 = (Panel)editformItem.FindControl("Panel1"); |
panel1.Visible = false; |
} |
else if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted)) |
{ |
GridEditFormInsertItem insertformItem = (GridEditFormInsertItem)e.Item; |
Panel panel1 = (Panel)insertformItem.FindControl("Panel1"); |
panel1.Visible = false; |
} |
} |
Thanks
Princy
0
Bill
Top achievements
Rank 2
answered on 08 May 2010, 01:43 AM
I tried this code and it didn't work as expected until I reversed the order of the if statements - check for the insert first.