locked
View All GridView Rows on Button Click from Datasource RRS feed

  • Question

  • User198251766 posted

    I have a app that has a text box and button used to search the data source and works as expected, I want to add another feature so that when the user clicks the button with a empty text box the entire SQL Datasource gridview will bind. I'm not really sure how to do this since I used the control parameter to perform my search. So basically I have no code behind. This what I have for my asp.net page

    <asp:GridView ID="grdEditPersonnel" runat="server" CssClass="panelEdit" AllowPaging="True"
                        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1"
                        CellPadding="3" RowStyle-Height="3px" ForeColor="Black" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" PageSize="20" AutoGenerateDeleteButton="True"
                        AutoGenerateEditButton="True">
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                SortExpression="ID" Visible="False" />
                            <asp:BoundField DataField="InvoiceEntered" DataFormatString="{0:d}" HeaderText="Entered on"
                                SortExpression="InvoiceEntered" />
                            <asp:BoundField DataField="RepoDate" DataFormatString="{0:d}" HeaderText="Repo Date"
                                SortExpression="RepoDate" />
                            <asp:BoundField DataField="AlscoInvoice" HeaderText="Invoice #" 
                                SortExpression="AlscoInvoice" />
                            <asp:BoundField DataField="WorkType" HeaderText="Type" 
                                SortExpression="WorkType" />
                            <asp:BoundField DataField="WorkClient" HeaderText="Vendor" 
                                SortExpression="WorkClient" />
                            <asp:BoundField DataField="WorkPrice" HeaderText="Price" SortExpression="WorkPrice"
                                DataFormatString="{0:c2}" />
                            <asp:BoundField DataField="OrderYear" HeaderText="Year" 
                                SortExpression="OrderYear" />
                            <asp:BoundField DataField="OrderMake" HeaderText="Make" 
                                SortExpression="OrderMake" />
                            <asp:BoundField DataField="OrderModel" HeaderText="Model" 
                                SortExpression="OrderModel" />
                            <asp:BoundField DataField="VinNum" HeaderText="VIN" SortExpression="VinNum" />
                            <asp:BoundField DataField="Debtor" HeaderText="Debtor Last Name" 
                                SortExpression="Debtor" />
                            <asp:BoundField DataField="StatKey" HeaderText="Keys" 
                                SortExpression="StatKey" />
                            <asp:BoundField DataField="StatRun" HeaderText="Operable" 
                                SortExpression="StatRun" />
                            <asp:BoundField DataField="StatStorage" HeaderText="Storage Status" 
                                SortExpression="StatStorage" />
                            <asp:BoundField DataField="PayStatus" HeaderText="Payment Status" 
                                SortExpression="PayStatus" />
                            <asp:BoundField DataField="SystemType" HeaderText="System Used" 
                                SortExpression="SystemType" />
                            <asp:BoundField DataField="SysInvoice" HeaderText="System Invoice" 
                                SortExpression="SysInvoice" />
                            <asp:BoundField DataField="SalesRep" HeaderText="Rep" 
                                SortExpression="SalesRep" />
                            <asp:BoundField DataField="RepoAgent" HeaderText="Repo By" 
                                SortExpression="RepoAgent" />
                            <asp:BoundField DataField="PayOut" HeaderText="Agent Payout" 
                                SortExpression="PayOut" />
                            <asp:BoundField DataField="NumberOfDays" HeaderText="Days On Lot" 
                                SortExpression="NumberOfDays" />
                        </Columns>
                        <FooterStyle BackColor="#F0F0F0" />
                        <HeaderStyle BackColor="#8d8e90" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                        <RowStyle Height="15px" BackColor="White" />
                        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#FBFBF2" />
                        <SortedAscendingHeaderStyle BackColor="#848384" />
                        <SortedDescendingCellStyle BackColor="#EAEAD3" />
                        <SortedDescendingHeaderStyle BackColor="#575357" />
                        <AlternatingRowStyle BackColor="#e6f2ff" ForeColor="#282828" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PayrollSystem_DBConnectionString1 %>"
                        ProviderName="<%$ ConnectionStrings:PayrollSystem_DBConnectionString1.ProviderName %>"
                        SelectCommand="SELECT * FROM [tblPersonnel] WHERE ([VinNum] = ?)" DeleteCommand="DELETE FROM tblPersonnel WHERE (ID = ?)"
                        InsertCommand="INSERT INTO tblPersonnel ID, RepoDate, InvoiceEntered, AlscoInvoice, WorkType, WorkClient, WorkPrice, OrderYear, OrderMake, OrderModel, VinNum, Debtor, StatKey, StatRun, StatStorage, PayStatus, SystemType, SysInvoice, SalesRep, RepoAgent, PayOut, NumberOfDays"
                        UpdateCommand="UPDATE tblPersonnel SET InvoiceEntered = ?, RepoDate = ?, AlscoInvoice = ?, WorkType = ?, WorkClient = ?, WorkPrice = ?, OrderYear = ?, OrderMake = ?, OrderModel = ?, VinNum = ?, Debtor = ?, StatKey = ?, StatRun = ?, StatStorage = ?, PayStatus = ?, SystemType = ?, SysInvoice = ?, SalesRep = ?, RepoAgent = ?, PayOut = ?, NumberOfDays = ? WHERE (ID = ?)"
                        CancelSelectOnNullParameter="False">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="txtBoxSearch" DefaultValue="%" Name="VinNum" 
                                PropertyName="Text" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>

    This is my weak cs code, I did try other tutorials but nothing provided any results

    public partial class frmEditInvoices : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
            Response.Cache.SetNoStore();
            
    
            grdEditPersonnel.Visible = true;
    
           
        }
    
    
    
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            grdEditPersonnel.Visible = true;
        }
    }

    All help is much appreciated!!

    609
    Tuesday, September 22, 2015 7:56 PM

Answers

  • User-1716253493 posted

    Modify this

    SelectCommand="SELECT * FROM [tblPersonnel] WHERE (CAST([VinNum] as VarChar) LIKE @VinNum)"

    If VinNum datatype is varchar simp[ly

    SelectCommand="SELECT * FROM [tblPersonnel] WHERE ([VinNum] LIKE @VinNum)"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 22, 2015 8:17 PM

All replies

  • User-1716253493 posted

    Modify this

    SelectCommand="SELECT * FROM [tblPersonnel] WHERE (CAST([VinNum] as VarChar) LIKE @VinNum)"

    If VinNum datatype is varchar simp[ly

    SelectCommand="SELECT * FROM [tblPersonnel] WHERE ([VinNum] LIKE @VinNum)"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 22, 2015 8:17 PM
  • User198251766 posted

    Thanks bud, that was exactly what I was looking for

    153
    Tuesday, September 22, 2015 8:52 PM
  • User198251766 posted

    208
    Tuesday, September 22, 2015 9:02 PM