Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to make a program in Visual Studio using asp.net that displays the results of a SQL Database in an HTML repeater table.  I'm attempting to filter the data within the table so that you are able to display members who are "termed" or members who are "active".

Here is my code so far

    <%@ Page Language="C#" AutoEventWireup="True" %>

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.2/css/jquery.dataTables.css">
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.js"></script>
    </head>
     <script runat="server">
     void Search_Click(object sender, EventArgs e)
     {
      <!-- This is the part I was most confused about.  I need help on what to put here -->
      @Title = DropDownList1.SelectedValue;
     }
    </script>
    <body>
    <form id="Form1" action="demo_form_action.asp" runat="server" method="get">
    <asp:Button ID="Submit1" OnClick="Search_Click"
            Text="Log Out" runat="server" />
		
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem Selected>Activated</asp:ListItem>
                <asp:ListItem>Termed</asp:ListItem>
            </asp:DropDownList>
            </div>



     <div>
      <asp:Repeater ID="Repeater1" runat="server" 
          DataSourceID="SqlDataSource1">
          <HeaderTemplate>

		<table id="table_id" class="display">
       <thead>
            <tr>
                <th>Subscriber ID</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Birthdate</th>
				<th>Provider ID</th>
				<th>Payer</th>
				<th>HICN</th>
				<th>Medicare No.</th>
				<th>Medicaid No.</th>
				<th>Status</th>
                
            </tr>
           </thead>
            <tbody>
        </HeaderTemplate>
           <ItemTemplate>
          <tr>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label1" 
                    text='<%# Eval("CoverageID") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                  <asp:Label runat="server" ID="Label2" 
                      text='<%# Eval("FirstName") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label3" 
                    text='<%# Eval("LastName") %>' />

                  <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label4" 
                    text='<%# Eval("DOB") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                  <asp:Label runat="server" ID="Label5" 
                      text='<%# Eval("ProviderID") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label6" 
                    text='<%# Eval("HPName") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label7" 
                    text='<%# Eval("HPOtherID") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label8" 
                    text='<%# Eval("MedicalID") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label9" 
                    text='<%# Eval("MedicareID") %>' />
              </td>
              <td bgcolor="#CCFFCC">
                <asp:Label runat="server" ID="Label10" 
                    text='<%# Eval("StatusName") %>' />
              </td>
              
          </tr>
          </ItemTemplate>

          <FooterTemplate>
              </tbody>
              </table>
          </FooterTemplate>
      </asp:Repeater>

      <asp:SqlDataSource 
          DataSourceMode = "Dataset"
          Enablecaching = "true"
         
          ConnectionString=
              "<%$ ConnectionStrings:UACConnectionString %>"
          ID="SqlDataSource1" runat="server" 
          SelectCommand="SELECT DISTINCT MemberCoverages.CoverageID, Members.FirstName, Members.LastName, Members.DOB, MemberCoverages.ProviderID, HealthPlans.HPName, MemberCoverages.HPOtherID, MemberCoverages.MedicalID, MemberCoverages.MedicareID, StatusCodes.StatusName
          FROM MemberCoverages
          Join Members
          ON MemberCoverages.MemberID=Members.MemberID
          Join HealthPlans
          ON MemberCoverages.HPID=HealthPlans.HPID
          Join StatusCodes
          ON Membercoverages.StatusID=StatusCodes.StatusID
           WHERE [TermDate] IS NULL AND StatusName = @Title;">
          <SelectParameters>
              <asp:ControlParameter Name ="Title" ControlID="DropDownList1" PropertyName="SelectedValue" />
          </SelectParameters>
      </asp:SqlDataSource>
     </div>
    </form>

    </body>
    </html>  

So my app starts by displaying all members with a StatusName of "Active".  And ideally, I want it to filter based off of the selected dropdown whenever the "Search_1" button is clicked.  However, whenever I change the dropdown to "Termed" and click the button, I receive an error page that says "HTTP Error 414. The request URL is too long".

So how can I make the Search_Click function filter based off of my dropdown choice?

I'm new to programming so please explain in a clear and basic terminology if you can.  I appreciate all help.  :) 
Posted
Comments
Ashi0891 27-Aug-14 13:11pm    
I don't know visual basic but I think you should bind your repeater in code behind. and then call it on button click and in IsPostBack rather than giving it in aspx code using sql datasource.
Member 11040863 27-Aug-14 13:33pm    
Thanks, I know this is a vague question, but do you know a resource or example on how I could do that?

1 solution

Simply put HTTP 414, the error message you are getting is self explanatory "The request URL is too long". Can you check whats so long in the url that the limit is crossed.
 
Share this answer
 
Comments
Member 11040863 27-Aug-14 13:18pm    
Rajiv: I have no idea why the URL would be so long. The URL disappears from the Nav Bar when I click it (presumably because it's too long to hold), so I can't really know what is in it.

I'm assuming there must be some kind of error in the code to make that happen.
Rajiv Gogoi 27-Aug-14 13:23pm    
@Title = DropDownList1.SelectedValue;
What does this line of code do. Where are you trying to assign you dropdown value.
Member 11040863 27-Aug-14 13:28pm    
It is supposed to be getting the value of my dropdown and assigning it to @Title, so that the ConnectionString of "WHERE [TermDate] IS NULL AND StatusName = @Title;">" will read @Title as whatever has been selected from the dropdown, and only data with the StatusName of the selected dropdown will show in my table.

But I'm guessing I'm doing it wrong.
Rajiv Gogoi 27-Aug-14 13:39pm    
Do you have to use a SQLDataSource ? I guess as the query is getting complicated, the url becomes large due to a large no of query string parameters. I am just assuming, not at all sure about it.
What I can suggest is, don't use SQLDataSource, use proper ADO.NET layer(basically C# classes) and write your logic in code behind. In that way, your code would be more maintanable, you will be able to put debug points and debug and also use best practices. SQLDataSouce is not the best way of connection to database and do CRUD.
Member 11040863 27-Aug-14 13:51pm    
Okay, thanks. I really appreciate it, I voted you as solution. I know this is a vague question, but do you know a resource or example on how I could write the code behind in the cs layer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900