How can I databind a gridpanel in a window based on a button click?

  1. #1

    How can I databind a gridpanel in a window based 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.

    Thanks for your help, it is greatly appreciated!
  2. #2
    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:	55 
Size:	55.7 KB 
ID:	1592

    Click image for larger version. 

Name:	WindowWithoutData.png 
Views:	48 
Size:	55.0 KB 
ID:	1593
  3. #3
    Geoffrey McGill
    Founder & CEO

Similar Threads

  1. Replies: 8
    Last Post: Jun 22, 2012, 2:48 PM
  2. 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
  3. Replies: 2
    Last Post: Mar 21, 2012, 11:06 AM
  4. Replies: 4
    Last Post: Sep 17, 2010, 10:33 PM
  5. Hide the grid coloum Based on Button Click
    By Dinesh.T in forum 1.x Help
    Replies: 1
    Last Post: Nov 17, 2009, 3:55 AM

Posting Permissions