Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net C# webforms GridView change embedded SQL statement

Hi

I have an ASP.net C# web forms project with the following GridView, Is it possible to change the SQL statement on a button click


                                        <asp:TemplateField HeaderText="Broker Follow Up Required" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" SortExpression="[Broker Follow Up Required]" ControlStyle-Width="80">

                                               <ItemTemplate>

                                                     <asp:Label ID="lblBroker_Follow_Up_Required" runat="server" Size="65" Text='<%# Bind("[Broker Follow Up Required]")%>' ToolTip="Type"></asp:Label>

                                                    </ItemTemplate>

                                               <ItemStyle HorizontalAlign="Left" Wrap="True" />

                                        </asp:TemplateField>


                                          

                                       </Columns>

                                          <EditRowStyle BackColor="#2461BF" />

                                          <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

                                          <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

                                          <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

                                          <RowStyle BackColor="#EFF3FB" />

                                          <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

                                          <SortedAscendingCellStyle BackColor="#F5F7FB" />

                                          <SortedAscendingHeaderStyle BackColor="#6D95E1" />

                                          <SortedDescendingCellStyle BackColor="#E9EBEF" />

                                          <SortedDescendingHeaderStyle BackColor="#4870BE" />

                                    </asp:GridView>   

                                   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"

                                       SelectCommand="SELECT * FROM [Brokers] Where Archived IS NULL" FilterExpression="[Broker Company] LIKE '{0}%' Or [Broker Full Name] LIKE '{0}%'

                                       Or [Email] LIKE '{0}%' Or [Type] LIKE '{0}%'" >

                                        <FilterParameters>

                                                <asp:ControlParameter Name="Search" ControlID="txtSearch" PropertyName="Text" />

                                        </FilterParameters>

                                   </asp:SqlDataSource>


ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dfke
dfke

Hi,

Like slightwv mentioned this can be achieved by using the SelectCommand property of the SqlDataSource control and updating its value in the code-behind.

Something like:

SqlDataSource1.SelectCommand = "YOUR NEW SQL STATEMENT";
GridView1.DataBind();

Open in new window


Cheers
I guess thanks for posting pretty much the exact same code provided in the link I posted, even down to the SqlDataSource1 and GridView1 object names?
Avatar of Murray Brown

ASKER

thanks