Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / Need help with Webdatagrid template data field
Need help with Webdatagrid template data field
New DiscussionPlease refer to this post first made by another person it that solution worked except after post back the template is gone, my template display an image button only when a criteria has been met then in that row an image button is displayed they can click on, in my case they click on it disappears. How do I get it to stay after a post back is performed?
Reference Link: http://ko.infragistics.com/community/forums/t/63560.aspx
Replies
-
0
Hello Sri Denduluri,
Thank you for posting in our forums!
If you are creating the templates dynamically, you need to set the cell's Template property on each postback.
If you need further assistance with this, please let me know and I will be glad to help.
-
0
Hi Michael,
yes I know I have to re-set the cells template after postback but which event do I use to do this, and I don't have to make repeated database calls to do this do I? Cuz it uses value from a table to determine which cell is assign the template or not?
-
0
Hi Sri Denduluri,
Normally, I would recommend using Page_Load event for assigning the template, but since you need to do this on a conditional basis, the WebDataGrid's InitializeRow event may work best for you. You can use the arguments in this event to check the state of the entire record.
As for hitting your database, it is recommended to store your records or values in some memory like the Session state for each postback. This helps mitigate db calls except when you decide they are needed.
If you have any further questions or concerns with this, please let me know.
Please note that I will be out of the office for the holidays until Jan. 3. If you need immediate assistance with this case, email DSmanager@infragistics.com and link this forum thread.
-
0
hi Michael, I have another problem I got the template to load, by storing the data table in memory (session), and it loads fine after postback, now have another problem. The template contains control, a usercontrol is one of the many controls it contains (see below 'UserControl'), now the problem is this, when rowInitialize, and or when Page_Load occurs, and it calls the Usercontrols Page_Load event, the controls (see below 'lblHeader', 'grdLabResults') are null, why is this shouldn't this be automatic, when the controls have been created as I have done below in the Usercontrol page file, also see my code-behind file as well.
UserControl (LabResults)
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucLabResults.ascx.cs" Inherits="AwareDocEduWeb.UserControls.ucLabResults" %><div></div><div id="header" align="center">
<asp:Label ID="lblHeader" runat="server" Text="" Font-Size="XX-Large"></asp:Label>
</div><div>
</div><div style="margin: 20px 20px 20px 20px"><asp:GridView ID="grdLabResults" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" Font-Names="Arial" Font-Size="8pt" Width="800px" OnRowCommand="grdLabResults_RowCommand" OnLoad="grdLabResults_Load">
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:BoundField DataField="Item Name" HeaderText="Item Name" />
<asp:BoundField DataField="Order Name" HeaderText="Order Name" />
<asp:TemplateField HeaderText="Previous">
<ItemTemplate>
<asp:ImageButton ID="imgPrev" runat="server" CommandName="Previous" CommandArgument='<%# string.Format("{0}%{1}%{2}", Eval("OrderID"), Eval("Arrival Date"), Eval("Item Name")) %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:ImageButton ID="imgDesc" runat="server" CommandName="Description" CommandArgument='<%# Eval("Value") %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Value" HeaderText="Value" />
<asp:BoundField DataField="H/L" HeaderText="H/L" />
<asp:BoundField DataField="Range" HeaderText="Range" /><asp:BoundField DataField="Arrival Date" HeaderText="Arrival Date" />
<asp:BoundField DataField="OrderID" HeaderText="OrderID" Visible="False" />
<asp:BoundField DataField="Arrival" HeaderText="Arrival" Visible="False" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" Height="30px" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" Height="20px" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView></div>Usercontrol (LabResults) Code-Behindpublic partial class ucLabResults : System.Web.UI.UserControl
{protected void Page_Load(object sender, EventArgs e)
{
try
{
this.FillLabResultsGrid(); // put a break point here u will see that 'lblHeader' and 'grdLabResults' is nullthis.lblHeader.Text = "Lab Results for " + "Some Patient name";
}
catch (Exception ex)
{
Common.CommonFacade.CommonFacadeAccess.LogError(ex, this._UserID);
}
}}ModalPopup Templatepublic abstract class ModalPopupItemTemplate : System.Web.UI.ITemplate
{
#region "Variables"private Page _MyParentForm;private ImageButton _btnTargetControl = new ImageButton();
private ModalPopupExtender _ModalMainPopupExtender = new ModalPopupExtender();
private Panel _PanelPopupControl = new Panel();
private HtmlGenericControl _div1 = new HtmlGenericControl("div");
private HtmlGenericControl _div2 = new HtmlGenericControl("div");
private UserControl _ucMainUserControl = null;
private Button _btnOkControl = new Button();private readonly List<Control> _ListAdditionalContainerControls = new List<Control>();#endregion#region "Properties"public Page MyParentForm
{
get { return _MyParentForm; }
}
public ImageButton BtnTargetControl
{
get { return _btnTargetControl; }
}public ModalPopupExtender ModalMainPopupExtender
{
get { return _ModalMainPopupExtender; }
}public Panel PanelPopupControl
{
get { return _PanelPopupControl; }
}protected HtmlGenericControl Div1
{
get { return _div1; }
}protected HtmlGenericControl Div2
{
get { return _div2; }
}protected UserControl ucMainUserControl
{
get { return _ucMainUserControl; }
set { _ucMainUserControl = value; }
}protected Button BtnOkControl
{
get { return _btnOkControl; }
}protected List<Control> ListAdditionalContainerControls
{
get { return _ListAdditionalContainerControls; }
}#endregion#region "Constructor"protected ModalPopupItemTemplate()
{}protected ModalPopupItemTemplate(Page myParentForm, UserControl uc)
: this()
{
_ucMainUserControl = uc;
_MyParentForm = myParentForm;this.Init();
}#endregion#region ITemplate Membersprotected void Init()
{
BtnTargetControl.ID = "btnTargetControl";ModalMainPopupExtender.TargetControlID = "btnTargetControl";
ModalMainPopupExtender.PopupControlID = "PanelPopupControl";
ModalMainPopupExtender.OkControlID = "btnOkControl";
ModalMainPopupExtender.DropShadow = true;PanelPopupControl.ID = "PanelPopupControl";
PanelPopupControl.HorizontalAlign = HorizontalAlign.Center;
PanelPopupControl.BackColor = Color.White;
PanelPopupControl.Height = new Unit(450);
PanelPopupControl.Width = new Unit(400);
PanelPopupControl.Style.Add(HtmlTextWriterStyle.Display, "none");
PanelPopupControl.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid");
PanelPopupControl.Style.Add(HtmlTextWriterStyle.BorderWidth, "2px");
PanelPopupControl.Style.Add(HtmlTextWriterStyle.BorderColor, "black");
PanelPopupControl.Style.Add("align-items", "center");
PanelPopupControl.Controls.Add(Div1);
PanelPopupControl.Controls.Add(Div2);if (ucMainUserControl == null)
{
ucMainUserControl = new UserControl();Label lblHeader = new Label();
var divInner = new HtmlGenericControl("div");divInner.Style.Add(HtmlTextWriterStyle.VerticalAlign, "center");
divInner.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
divInner.Style.Add("align-items", "center");lblHeader.Text = "<h1>You need to add a custom user Control</h1>";divInner.Controls.Add(lblHeader);
ucMainUserControl.Controls.Add(divInner);
}ucMainUserControl.ID = "ucMainUserControl1";BtnOkControl.ID = "btnOkControl";Div1.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
Div1.Style.Add(HtmlTextWriterStyle.Height, "400px");
Div1.Controls.Add(ucMainUserControl);Div2.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
Div2.Controls.Add(BtnOkControl);
}public void InstantiateIn(Control container)
{
container.Controls.Add(BtnTargetControl);if (_ListAdditionalContainerControls.Any())
{
foreach (var c in _ListAdditionalContainerControls)
container.Controls.Add(c);
}container.Controls.Add(ModalMainPopupExtender);
container.Controls.Add(PanelPopupControl);
}#endregion
} -
0
Sri,
The objects defined in the markup don't have instances created when creating the UserControl with new. To address this, use Page.LoadControl to instantiate the UserControl to address this. The same issue is addressed in the following question on stackoverflow:
http://stackoverflow.com/questions/2275625/asp-net-custom-user-control-to-add-dynamically
Let me know if you have any questions with this matter.
-
-
- You must be logged in to reply to this topic.
Suggested Discussions
Mouse-hover in data-grid from field in data-grid
I am roughly on latest AG/ID (14.2). I have a data grid which represents scenarios (name, start, en…Please help: batchEditing isn't a know property of 'igx-grid
I want to enable batch editing for a igx-grid to allow commitment of edited rows to a database. But…need help :( on Grid Export to excel set currency format according to localization used for grid and export two grid in same workbook different sheet
Hi I have two problems 1. how to localize excel like while exporting excel i am setting the currenc…Help! Major performance issues with 1,000,000 rows and formula columns with sorting, filtering and grouping
I have a UltraGrid that is currently getting completed crushed performance wise in my Windows deskt…Tags
Created by
Created on
Dec 22, 2016 5:46 PM
Last activity on
Dec 22, 2016 5:46 PM