?
Solved

How to prevent a Gridview to display on page_load

Posted on 2009-05-08
4
Medium Priority
?
285 Views
Last Modified: 2012-05-06
I have a Gridview that is displayed directly when you enter the page.

I want it to show first when I submit a button.....

I've tried to set it to Visible="false" and to "True" when I submit the button but this is'nt a good solution.
<asp:GridView ID="GridView2" Visible="false" DataKeyNames="EventId,AttendeeID" Width="700px" 
                        runat="server" AllowPaging="True" PageSize="30" AutoGenerateColumns="False" 
                        DataSourceID="SqlDataSource1" AllowSorting="True">
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <Columns>
                    <asp:BoundField DataField="Fname" HeaderText="First Name" SortExpression="Fname" 
                    ItemStyle-Width="150px" >
                    </asp:BoundField>
                    <asp:BoundField DataField="Lname" HeaderText="Last Name" SortExpression="Lname" 
                    ItemStyle-Width="150px" >
                    </asp:BoundField>
                    <asp:BoundField DataField="EMail" HeaderText="e-mail" SortExpression="EMail" 
                    ItemStyle-Width="200px" >
                    </asp:BoundField>
                    <asp:BoundField DataField="RegDate" HeaderText="Registered (UTC)" 
                        SortExpression="RegDate" ItemStyle-Width="150px" >
 
                    </asp:BoundField>
                    
                    <asp:TemplateField ShowHeader="false" ItemStyle-Width="25">
                        <ItemTemplate>
                            <asp:HyperLink ID="myHyperLink" runat="server" NavigateUrl='<%# Eval("AttendeeID", "..\PAGES\AdminEditReg.aspx?atid={0}")%>' ImageUrl="..\..\images\edit.gif" />
                        </ItemTemplate>
                    
                    </asp:TemplateField>
                    <asp:TemplateField ShowHeader="false" ItemStyle-Width="25">
                        <ItemTemplate>
                            <asp:ImageButton ID="button" runat="server" CausesValidation="false" CommandName="Delete" 
                            OnClientClick='return confirm("Are you sure you want to delete?");' ImageUrl="..\..\images\delete.gif" /> 
                        </ItemTemplate>
 
                    </asp:TemplateField>
                </Columns>     
            </asp:GridView>
                </td>
            </tr>
         </table>   
      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
 
            ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" 
            
             SelectCommand="SELECT * FROM [Attendees] WHERE ([EventId] = @EventId)" FilterExpression="Fname like '%{0}%'
                or Lname like '%{1}%' or EMail like '%{2}%' " 
             
             DeleteCommand="DELETE FROM [Attendees] WHERE [AttendeeID] = @AttendeeID">
             
                <DeleteParameters> 
                    <asp:Parameter Name="AttendeeID" Type="Int32" />
                </DeleteParameters>
                <SelectParameters>
                    <asp:SessionParameter Name="EventId" SessionField="RegEventId" 
                        Type="Int32" />
                </SelectParameters>
                <FilterParameters>
                    <asp:ControlParameter Name="Fname" ControlID="searchTextBox" 
                        PropertyName="Text" />
                    <asp:ControlParameter Name="Lname" ControlID="searchTextBox" 
                        PropertyName="Text" />
                    <asp:ControlParameter Name="EMail" ControlID="searchTextBox" 
                        PropertyName="Text" />    
                </FilterParameters>
            
        </asp:SqlDataSource>

Open in new window

0
Comment
Question by:mattegol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24336739
"I've tried to set it to Visible="false" and to "True" when I submit the button but this is'nt a good solution."
Why? it`s not working you have a philosophic objection against it?
0
 

Author Comment

by:mattegol
ID: 24337643
The user is only going to use the gridview sometimes and I don't wan't to get the database involved if I dont have to. If the gridview has lets say >3000 rows is slows the page down doesn't it?

Otherwise Visible="false" works fine for me...
0
 
LVL 18

Accepted Solution

by:
David Robitaille earned 2000 total points
ID: 24337678
then just dont bind it (leave "DataSourceID" blank)
then, whan you set it to visible to true, set the DataSourceID and call databind
GridView2.visible=true
GridView2.DataSourceID ="SqlDataSource1"
GridView2.databind
 
0
 

Author Closing Comment

by:mattegol
ID: 31579343
Thank you, simple solution just like I like it
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question