Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

linking submit button to gridview

I am trying to create a search script of db records.

there are x4 text fields -- so the user can try any of those x4 fields if cannot user cannot remember the exact db record number etc.

what I am not getting to work is when user presses the 'submit' button, this then fires up a sql search and then display via the gridview.

how do I link this ?
//--text fields and submit button
 
 
<table align="left">
                    <tr>
                        <td style="width: 123px; text-align: right">
                            <span style="font-size: 10pt; font-family: @Arial Unicode MS">Master Account&nbsp;</span>
                        </td>
                        <td style="width: 86px; text-align: left">
                            <asp:TextBox ID="TextBox_MasterAccount" runat="server" 
                                Font-Names="Arial Unicode MS" Font-Size="10pt"
                                Width="120px"></asp:TextBox></td>
                        <td style="width: 60px">
                        </td>
                        <td style="width: 144px; text-align: right">
                            <span style="font-size: 10pt"><span style="font-family: @Arial Unicode MS">Applicant
                                First Name&nbsp;</span> </span>
                        </td>
                        <td style="width: 125px">
                            <asp:TextBox ID="TextBox_FirstNameApp1" runat="server" 
                                Font-Names="Arial Unicode MS" Font-Size="10pt"
                                Width="180px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 123px; text-align: right">
                            <span style="font-size: 10pt; font-family: @Arial Unicode MS">Client Case&nbsp;</span>
                        </td>
                        <td style="width: 86px">
                            <asp:TextBox ID="TextBox_ClientCase" runat="server" 
                                Font-Names="Arial Unicode MS" Font-Size="10pt"
                                Width="120px" Wrap="False"></asp:TextBox></td>
                        <td style="width: 60px">
                        </td>
                        <td style="width: 144px; text-align: right">
                            <span style="font-size: 10pt"><span style="font-family: @Arial Unicode MS">Applicant
                                Last Name&nbsp;</span> </span>
                        </td>
                        <td style="width: 125px">
                            <asp:TextBox ID="TextBox_LastNameApp1" runat="server" 
                                Font-Names="Arial Unicode MS" Font-Size="10pt"
                                Width="180px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 123px; text-align: right">
                        </td>
                        <td style="width: 86px">
                        </td>
                        <td style="width: 60px">
                        </td>
                        <td style="width: 144px">
                        </td>
                        <td style="width: 125px">
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 123px; text-align: right">
                            <span style="font-size: 10pt"><span style="font-family: @Arial Unicode MS"></span></span>
                        </td>
                        <td style="width: 86px; text-align: left">
                            <asp:Button ID="Button_FindCase" runat="server" Font-Bold="True" Font-Names="Arial Unicode MS"
                                Font-Size="10pt" Text="Find Case" Width="100px" 
                                OnClick="Button_FindCase_Click" ondatabinding="GridViewSearch_Load" /></td>
                        <td colspan="3" style="text-align: left">
                            <asp:CheckBox ID="CheckBox_ActiveCases" runat="server" Checked="True" Font-Names="Arial Unicode MS"
                                Font-Size="8pt" Text="Search Active Cases Only" /></td>
                    </tr>
                </table>
 
//--datagridview--------------
 
<asp:GridView ID="GridViewSearch" runat="server" AllowPaging="True" 
                    AutoGenerateColumns="False" DataSourceID="SqlDataSource_SearchClientCasesMain" 
                    Font-Names="Arial Unicode MS" Font-Size="10pt" GridLines="None" Width="715px" 
                                CellPadding="4" ForeColor="#333333" 
                                PageSize="5" style="text-align: left">
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <PagerStyle ForeColor="Black" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle Font-Bold="True" ForeColor="Black" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="Black" />
                </asp:GridView>

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I don't understand what you mean by "link this".

Bob
Avatar of amillyard

ASKER

TheLearnedOne:

type text in 1 or more of the text entry fields

press 'submit' button -- which then fires up sql select statement within the gridview

page onloading - the gridview fires automatically, but looking instead to propogate the gridview each time a 'submit' button is pressed.   (thats what I am reffering to as linked -- associated action)
1) 'GridViewSearch' is bound to 'SqlDataSource_SearchClientCasesMain'.

2) I don't see ''SqlDataSource_SearchClientCasesMain', so does it have parameters defined?

Bob

<asp:SqlDataSource ID="SqlDataSource_SearchClientCasesMain" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>"              
                        SelectCommand="SELECT [ClientCase_ID], [MasterAccount_ID], [DisplayNameApp1], [FirstNameApp1], [LastNameApp1] FROM [ClientCases] WHERE (([MasterAccount_ID] = @MasterAccount_ID) OR ([ClientCase_ID] = @ClientCase_ID) OR ([FirstNameApp1] = @FirstNameApp1) OR ([LastNameApp1] = @LastNameApp1)) ORDER BY [DisplayNameApp1]">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="TextBox_MasterAccount" Name="MasterAccount_ID" 
                                PropertyName="Text" Type="Int32" />
                            <asp:ControlParameter ControlID="TextBox_ClientCase" Name="ClientCase_ID" 
                                PropertyName="Text" Type="Int32" />
                            <asp:ControlParameter ControlID="TextBox_FirstNameApp1" Name="FirstNameApp1" 
                                PropertyName="Text" Type="String" />
                            <asp:ControlParameter ControlID="TextBox_LastNameApp1" Name="LastNameApp1" 
                                PropertyName="Text" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>

Open in new window

You have control parameters, so the GridView should be displaying values based on the parameterized SelectCommand.  I am still failing to see what the problem is.

Bob
Bob, when I press the submit button, nothing is happening -- web-page just refreshes (have entered known record data to search on)
Do the TextBox controls, like TextBox_MasterAccount, have the values that you entered before the page posts back after the post back?

Bob
Bob, I am assuming so -- as I type these entries on-screen manually each time when testing
Submit button -- look at TextBox_MasterAccount on the page.  What value does it have?

Bob
whatever is typed into TextBox_MasterAccount
Bob, I am assuming you are asking about the value, to confirm if a value is being captured.

the value appears to be captured, but by pressing the 'submit' button does not seem to be firing up the datagrid
Expected processing:

1) You enter a value into the TextBox controls.

2) You press the <submit> button, and the page posts back.

3) The SqlDataSource pulls the value from the TextBox controls as the parameters for the Select query.

4) The GridView displays the results of the Select query.

5) >>does not seem to be firing up the datagrid
    Does this mean that the GridView is blank?

Bob
yes, correct -- gridview does not appear (normally happens when there is no content found)
What do you want to happen when there aren't any records found?  Is this a case where it didn't get records when it should have?

Bob
just a text message to indicate no records found

at the moment there is no message appears as I know a blank screen also means no results found.

I know the text entry is correct -- as there x4 different fields to choose from and I know the exact details of those record details .. i.e. MasterAccount, ClientCase etc -- so tying in any of these should return a result -- albeit a single record, the records are there.

has the button press and then firing up of the sql search / datagrid been associated correctly?   after pressing the submit button is the scripting programmed correctly to initiate the sql search etc. ?
You can test the SqlDataSource's results like this:

Bob
        DataView products = (DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
 
        int count = products.Count;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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
Bob,  I have finally got this routine to work -- cleared down the grid etc and started again...but this time, I digested your inputs.   I now realise that there is no need to actually link the submit button to the datagrid as such (just thinking logically -- i.e. press the submit button, then there must be something to code for the next action) -- as the postback generates the datagrid update etc.

Again, many thanks for your valued and apprieated time and efforts with this enquiry.
hi,
can you post some the code-behind to see what action are taken on the Button_FindCase_Click and GridViewSearch_Load events?
thank you,
sam