How can I show a window and databind a gridpanel in that window on a button click?

  1. #1

    How can I show a window and databind a gridpanel in that window on a button click?

    This is pretty complicated, so I'll do my best to explain my issue.

    I have a gridpanel with a CheckboxSelectionModel. When I select a row and click a button, I would like to take a value from the CheckboxSelectionModel and use that as a parameter in my SqlDataSource and show a gridpanel in another window with the data from the SqlDataSource. For some reason, if I hardcode in the value of the parameter for the SqlDataSource, the gridpanel shows up fine. However, as soon as I try getting the parameter value from the CheckboxSelectionModel, the gridpanel does not show up.

    Here is some code that may help you better understand the problem:

    Markup
    <asp:SqlDataSource ID="sdsVisitHistory" runat="server" OnSelecting="sdsVisitHistory_Selecting"
         ConnectionString="<%$ ConnectionStrings:COREInfoDeskConnection %>"
         ProviderName="<%$ ConnectionStrings:COREInfoDeskConnection.ProviderName %>"
         SelectCommand="SELECT visitid, purpose, purposespecific, accommodations, accommspecific, spadmit, rhadmit,
                               TO_CHAR(checkin, 'MM/DD/YYYY') AS checkin,
                               TO_CHAR(checkout, 'MM/DD/YYYY') AS checkout
                          FROM infodesk.visit
                         WHERE visitorid = :visitorid">
        <SelectParameters>
           <asp:Parameter Name="visitorid" />
        </SelectParameters>
    </asp:SqlDataSource>
    	
    <ext:Window ID="winVisitorHistory" runat="server" Title="Visitor History" Icon="Vcard" Width="805" Height="500"
        Modal="true" Hidden="true" Layout="Fit">
        <Items>
            <ext:FormPanel ID="fpnlVisitHistory" runat="server" Padding="3"
                ButtonAlign="Left" Width="392" AnchorVertical="100%">
                <Content>
                    <ext:Label ID="txtVisitorName" runat="server" FieldLabel="Visitor" AnchorHorizontal="95%" />
                    <ext:GridPanel ID="gpnlVisitHistory" runat="server" AutoDataBind="true" Frame="false"
                        StripeRows="true" TrackMouseOver="true" BodyBorder="true" AutoHeight="true" Border="true"
                        AutoScroll="true">
                        <Store>
                            <ext:Store ID="dstoreVisitHistory" runat="server" DataSourceID="sdsVisitHistory" AutoDataBind="true">
                               <Reader>
                                  <ext:JsonReader IDProperty="VISITID">
                                     <Fields>
                                        <ext:RecordField Name="PURPOSE" />
                                        <ext:RecordField Name="PURPOSESPECIFIC" />
                                        <ext:RecordField Name="ACCOMMODATIONS" />
                                        <ext:RecordField Name="ACCOMMSPECIFIC" />
                                        <ext:RecordField Name="SPADMIT" />
                                        <ext:RecordField Name="RHADMIT" />
                                        <ext:RecordField Name="CHECKIN" />
                                        <ext:RecordField Name="CHECKOUT" />
                                     </Fields>
                                  </ext:JsonReader>
                               </Reader>
                            </ext:Store>
                        </Store>
                        <ColumnModel ID="cmdlVisitorHistory" runat="server">
                            <Columns>
                                <ext:Column ColumnID="colPurpose" DataIndex="PURPOSE" Header="Purpose" Width="150" />
                                <ext:Column ColumnID="colPurposeSpecific" DataIndex="PURPOSESPECIFIC" Header="Purpose 2" Width="150" />
                                <ext:Column ColumnID="colAccommodations" DataIndex="ACCOMMODATIONS" Header="Accommodations" Width="150" />
                                <ext:Column ColumnID="colAccomSpecific" DataIndex="ACCOMMSPECIFIC" Header="Accommodations 2" Width="150" />
                                <ext:Column ColumnID="colSPAdmit" DataIndex="SPADMIT" Header="SC" Width="25" />
                                <ext:Column ColumnID="colRHAdmit" DataIndex="RHADMIT" Header="RH" Width="25" />
                                <ext:Column ColumnID="colCheckin" DataIndex="CHECKIN" Header="Checkin" Width="65" />
                                <ext:Column ColumnID="colCheckout" DataIndex="CHECKOUT" Header="Checkout" Width="65" />
                            </Columns>
                        </ColumnModel>
                    </ext:GridPanel>
                </Content>
           </ext:FormPanel>
       </Items>
    </ext:Window>
    C#
    protected void btnVisitHistory_Click(object sender, DirectEventArgs e)
    {
        Trace.Warn("btnVisitHistory_Click");
        if (this.CheckboxSelectionModel1.SelectedRows.Count == 1)
        {
            Trace.Warn((this.CheckboxSelectionModel1.SelectedRows.Count == 1).ToString());
            this.gpnlVisitHistory.DataBind();
            winVisitorHistory.Show();
        }
        else
        {
            Trace.Warn("false");
            lblVisitors.StyleSpec = "color:red; font-weight:bold;";
            lblVisitors.Text = "Only one visitor may be selected to view Visit History.";
        }
     
        Trace.Warn(gpnlVisitHistory.Items.Count.ToString());
    }
     
    protected void sdsVisitHistory_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        Trace.Warn("sdsVisitHistory_Selecting");
        string visitors = getCheckedVisitors();
     
        if (this.CheckboxSelectionModel1.SelectedRows.Count == 1)
        {
            lblVisitors.Text = String.Empty;
            sdsVisitHistory.SelectParameters.Clear();
            sdsVisitHistory.SelectParameters.Add("visitorid", visitors.TrimEnd(','));
            sdsVisitHistory.DataBind();
            Trace.Warn("visitorid", visitors.TrimEnd(','));
        }
        else
        {
            Trace.Warn("Cancel");
            e.Cancel = true;
        }
    }
    Using the Trace.Warn() I have verified that I am getting the correct value from the CheckboxSelectionModel, and my gpnlVisitHistory is giving the correct item count, but the gridpanel is not showing up in the window.

    Here are two screen shots that show the problem I am having. The first is when I hardcode the parameter into the query in the SqlDataSource. The second is when I set the value of the parameter in the sdsVisitHistory_Selecting Event.

    Click image for larger version. 

Name:	WindowWithData.png 
Views:	133 
Size:	55.7 KB 
ID:	1598

    Click image for larger version. 

Name:	WindowWithoutData.png 
Views:	122 
Size:	55.0 KB 
ID:	1599

    Thanks for your help, it is greatly appreciated!
  2. #2
    Please don't double post, see

    http://forums.ext.net/showthread.php...a-button-click

    Best to bump the original thread and provide more information.
    Geoffrey McGill
    Founder
  3. #3
    How do I delete the previous thread?

    If I need to put more information, please let me know what information you need. I believe I have put everything down that is relevant to the problem.
  4. #4

    Stack Trace

    Here is my stack trace and according to the number of rows returned, I should be seeing some rows in my gridpanel, but I'm not getting anything. Could someone PLEASE HELP!! Please let me know if you need any more information.

    aspx.page			Begin PreInit		
    aspx.page			End PreInit						0.00165663513100129	0.001657
    aspx.page			Begin Init						0.00169295259593049	0.000036
    aspx.page			End Init						0.00218742884919731	0.000494
    aspx.page			Begin InitComplete				0.00221145424907356	0.000024
    aspx.page			End InitComplete				0.00223436218849044	0.000023
    aspx.page			Begin LoadState					0.00225587330233312	0.000022
    aspx.page			End LoadState					0.00354430521197526	0.001288
    aspx.page			Begin ProcessPostData			0.00357056553277023	0.000026
    aspx.page			End ProcessPostData				0.00805940419801958	0.004489
    aspx.page			Begin PreLoad					0.0080951629327191	0.000036
    aspx.page			End PreLoad						0.00814516928827547	0.000050
    aspx.page			Begin Load						0.00816751849746267	0.000022
    sdsVisitHistory		Selecting						0.00885810906134718	0.000691
    					sdsVisitHistory_Selecting		0.00888520747748666	0.000027
    visitorid			1								0.00903327098835187	0.000148
    					0								0.00906148686495071	0.000028
    aspx.page			End Load						0.00928637578239692	0.000225
    aspx.page			Begin ProcessPostData Second Try	0.00931040118227317	0.000024
    aspx.page			End ProcessPostData Second Try	0.00938471230282061	0.000074
    aspx.page			Begin Raise ChangedEvents		0.00940650278177813	0.000022
    aspx.page			End Raise ChangedEvents			0.00943639484906601	0.000030
    aspx.page			Begin Raise PostBackEvent		0.00945790596290869	0.000022
    sdsVisitHistory		Selecting						0.0112416522211622	0.001784
    					sdsVisitHistory_Selecting		0.0112732204791391	0.000032
    visitorid			1								0.0114251951016121	0.000152
    					0								0.0114517347875219	0.000027
    sdsVisitHistory		Selected						0.0142258303778832	0.002774
    Connection String	Data Source=coredev;Persist Security Info=True;User ID=infodesk;Password=	
    													0.0142870113380332	0.000061
    Command				SELECT visitid, purpose, purposespecific, accommodations, accommspecific, spadmit, rhadmit,
                               TO_CHAR(checkin, 'MM/DD/YYYY') AS checkin,
                               TO_CHAR(checkout, 'MM/DD/YYYY') AS checkout
                          FROM infodesk.visit
                         WHERE visitorid = :visitorid	0.0143099192774501	0.000023
    visitorid			1 (String)						0.0143347827726708	0.000025
    Rows returned		9								0.0143576907120877	0.000023
    					0								0.0154838114900078	0.001126
    aspx.page			End Raise PostBackEvent			0.0155106305410324	0.000027
    aspx.page			Begin LoadComplete				0.0155327003851048	0.000022
    aspx.page			End LoadComplete				0.0158196083580455	0.000287
    aspx.page			Begin PreRender					0.0158492210602185	0.000030
    aspx.page			End PreRender					0.0181587324646009	0.002310
    aspx.page			Begin PreRenderComplete			0.0181866689760849	0.000028
    aspx.page			End PreRenderComplete			0.0183246753428159	0.000138
    aspx.page			Begin SaveState					0.0352103409790909	0.016886
    aspx.page			End SaveState					0.0390150144780971	0.003805
    aspx.page			Begin SaveStateComplete			0.0390443478151553	0.000029
    aspx.page			End SaveStateComplete			0.039107763696224	0.000063
    aspx.page			Begin Render					0.0391317890961002	0.000024
    sdsCheckoutCheck	Selecting						0.0521340002709842	0.013002
    sdsCheckoutCheck	Selected						0.0557853023219432	0.003651
    Connection String	Data Source=coredev;Persist Security Info=True;User ID=infodesk;Password=	
    													0.055902635670176	0.000117
    Command				SELECT visitorid, visitid, firstname, lastname,
                                TO_CHAR(checkin, 'MM/DD/YYYY') as checkin,
                                TO_CHAR(validthrough, 'MM/DD/YYYY') as validthroughdisplay,
                                validthrough as validthroughdate
                           FROM infodesk.visit
                           JOIN infodesk.visitor USING(visitorid)
                          WHERE checkout IS NULL
                          ORDER BY validthrough			0.0559274991653967	0.000025
    Rows returned		21								0.0559540388513065	0.000027
    aspx.page			End Render						0.078545457593074	0.022591
  5. #5
    Hi,

    Instead of setting AutoDataBind="true" on the Store, try calling .DataBind() on the Store when you set the .DataSource property.

    Maybe after that change, and based on the code you have above, the GridPanel should bind on Page_Load, but will be hidden.

    As well, change <Content> to <Items>.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 4
    Last Post: Jul 17, 2012, 9:33 PM
  2. [CLOSED] how to close window after click button in this window
    By ViDom in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Jun 22, 2012, 2:48 PM
  3. Create new window dynamically on button click from another window
    By softlabsgroup.support in forum 1.x Help
    Replies: 6
    Last Post: May 01, 2012, 9:26 AM
  4. Replies: 2
    Last Post: Mar 21, 2012, 11:06 AM
  5. Replies: 2
    Last Post: Sep 09, 2010, 8:25 PM

Posting Permissions