Skip to content

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 Discussion
Sri Denduluri
Sri Denduluri asked on Dec 22, 2016 5:46 PM

Please 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

Sign In to post a reply

Replies

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Dec 15, 2016 8:29 PM

    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
      Sri Denduluri
      Sri Denduluri answered on Dec 16, 2016 4:27 PM

      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
        [Infragistics] Michael H.
        [Infragistics] Michael H. answered on Dec 17, 2016 12:41 AM

         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
        Sri Denduluri
        Sri Denduluri answered on Dec 19, 2016 3:15 PM

        ok, I will try that

      • 0
        Sri Denduluri
        Sri Denduluri answered on Dec 19, 2016 5:06 PM

        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-Behind

        public 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 null
                        this.lblHeader.Text = "Lab Results for " + "Some Patient name";
                    }
                    catch (Exception ex)
                    {
                        Common.CommonFacade.CommonFacadeAccess.LogError(ex, this._UserID);
                    }
                }
        }
        ModalPopup Template
        public 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 Members
                protected 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
        Michael Peterson
        Michael Peterson answered on Dec 20, 2016 3:30 PM

        Hello Sri Denduluri,

        Thank you for the update. So far I have been unable to reproduce the behavior you describe. How are you creating the user controls in your main page? Can you please attach an isolated sample that reproduces the issue?

      • 0
        Sri Denduluri
        Sri Denduluri answered on Dec 21, 2016 1:19 PM

        hi mike, I create a demo for u, when u run it I hard coded a break point when u hover over the control u wil see that it is null. I need tyur email address so I can send directly to you?

      • 0
        Michael Peterson
        Michael Peterson answered on Dec 21, 2016 4:12 PM

        Hello Sri,

        I have made a private case with the ID CAS-179783-L9G7F5 for this matter. You will receive an email with a link to where you can update the case and attach your sample.

      • 0
        Alan Halama
        Alan Halama answered on Dec 22, 2016 5:46 PM

        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.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Sri Denduluri
Favorites
0
Replies
9
Created On
Dec 22, 2016
Last Post
9 years, 7 months ago

Suggested Discussions

Created by

Created on

Dec 22, 2016 5:46 PM

Last activity on

Dec 22, 2016 5:46 PM