Avatar of Romacali
Romacali
 asked on

ddl seach

Hello,

How can I write the case selection for my search page.. I started from a expert help, but I have no idea how can I say :


            case 1: //teens  ddl = 1 ????
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults dd = 2 ???
                storedProcName = "sp_SFParticipantSearch_adult";
                break;

thanks,

private void Bind_Search()
    {
        string storedProcName = string.Empty;
        switch (int.Parse(ddlParticipantType.SelectedValue))
        {
            case 1: //teens 
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults
                storedProcName = "sp_SFParticipantSearch_adult";
                break;
            case 3: //seniors
                storedProcName = "sp_SFParticipantSearch_senior";
                break;
            case 4: //staff
                storedProcName = "sp_SFParticipantSearch_staff";
                break;
            case 0: //nothing selected. Could display error here or go with a default stored proc
                throw new NotImplementedException("No Type selected. Not sure of desired behavior");


                SqlCommand cmd3 = new SqlCommand("storedProcName", myConnection);
                cmd3.CommandType = CommandType.StoredProcedure;
                // Add your parameters here
                cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
                cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"].ToString()));

                myConnection.Open();

                SqlDataReader reader = cmd3.ExecuteReader();

                gridsearch.DataSource = reader;
                gridsearch.DataBind();

                reader.Close();
                myConnection.Close();
        }
    }

Open in new window

C#ASP

Avatar of undefined
Last Comment
Romacali

8/22/2022 - Mon
pradyahuja


private void Bind_Search()
    {
        string storedProcName = string.Empty;
        switch (int.Parse(ddlParticipantType.SelectedValue))
        {
            case 1: //teens 
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults
                storedProcName = "sp_SFParticipantSearch_adult";
                break;
            case 3: //seniors
                storedProcName = "sp_SFParticipantSearch_senior";
                break;
            case 4: //staff
                storedProcName = "sp_SFParticipantSearch_staff";
                break;
            case 0: //nothing selected. Could display error here or go with a default stored proc
                throw new NotImplementedException("No Type selected. Not sure of desired behavior");


                SqlCommand cmd3 = new SqlCommand(storedProcName, myConnection);
                cmd3.CommandType = CommandType.StoredProcedure;
                // Add your parameters here
                cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
                cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"].ToString()));

                myConnection.Open();

                SqlDataReader reader = cmd3.ExecuteReader();

                gridsearch.DataSource = reader;
                gridsearch.DataBind();

                reader.Close();
                myConnection.Close();
        }
    }

Open in new window

Rajar Ahmed

Hi Romacali,

 try this ,

Hope this helps
Meeran 03:)

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="JavaScript">
      function ShowPopup() {
     window.showModalDialog("test.aspx", "Dialog",
     "dialogWidth:500px;dialogHeight:800px;");
}
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
         <asp:DropDownList ID="ddlParticipantType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdown_change">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
        <asp:ListItem>0</asp:ListItem>
        </asp:DropDownList>
                
     </div>
    </form>
</body>
</html>

Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
     
        
    }
    private void Bind_Search()
    {
        string storedProcName = string.Empty;
        switch (int.Parse(ddlParticipantType.SelectedValue))
        {
            case 1: //teens 
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults
                storedProcName = "sp_SFParticipantSearch_adult";
                break;
            case 3: //seniors
                storedProcName = "sp_SFParticipantSearch_senior";
                break;
            case 4: //staff
                storedProcName = "sp_SFParticipantSearch_staff";
                break;
            case 0: //nothing selected. Could display error here or go with a default storedproc
                storedProcName = "";
                break;  
        }

        if (String.IsNullOrEmpty(storedProcName) == false)
        {
            Response.Write(storedProcName);
            SqlCommand cmd3 = new SqlCommand(storedProcName, myConnection);
            cmd3.CommandType = CommandType.StoredProcedure;
            // Add your parameters here
            cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
            cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"].ToString()));

            myConnection.Open();

            SqlDataReader reader = cmd3.ExecuteReader();

            gridsearch.DataSource = reader;
            gridsearch.DataBind();

            reader.Close();
            myConnection.Close();

        }
        else
        {
            Response.Write("No store Procedures");
        }
    }

    protected void dropdown_change(object sender, EventArgs e)
    {
        Bind_Search();
    }
}

Open in new window

Romacali

ASKER
I tried and nothing happened :( not sure not sure what to do

here is how my ddl:

 <asp:DropDownList AutoPostBack="true" runat="server" ID="ddlParticipantType" CssClass="form_input" Width="130px">
    <asp:ListItem Value="0" Text="Select" />
    <asp:ListItem Value="1" Text="Teens" />
    <asp:ListItem Value="2" Text="Adults" />
     <asp:ListItem Value="3" Text="Seniors" />
    <asp:ListItem Value="4" Text="Staff" />
    </asp:DropDownList>    
             
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Rajar Ahmed

Add this::

<asp:DropDownList AutoPostBack="true" runat="server" OnSelectedIndexChanged="dropdown_change"   ID="ddlParticipantType" CssClass="form_input" Width="130px">
     <asp:ListItem Value="0" Text="Select" />
    <asp:ListItem  Value="1" Text="Teens" />
    <asp:ListItem Value="2"  Text="Adults" />
     <asp:ListItem Value="3" Text="Seniors"  />
    <asp:ListItem Value="4" Text="Staff" />
</asp:DropDownList>    





<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    </head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList AutoPostBack="true" runat="server" ID="ddlParticipantType" 
    OnSelectedIndexChanged="dropdown_change" CssClass="form_input" Width="130px">
    <asp:ListItem Value="0" Text="Select" />
    <asp:ListItem Value="1" Text="Teens" />
    <asp:ListItem Value="2" Text="Adults" />
     <asp:ListItem Value="3" Text="Seniors" />
    <asp:ListItem Value="4" Text="Staff" />
    </asp:DropDownList>                   
     </div>
    </form>
</body>
</html>

Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
     
        
    }
    private void Bind_Search()
    {
        string storedProcName = string.Empty;
        switch (int.Parse(ddlParticipantType.SelectedValue))
        {
            case 1: //teens 
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults
                storedProcName = "sp_SFParticipantSearch_adult";
                break;
            case 3: //seniors
                storedProcName = "sp_SFParticipantSearch_senior";
                break;
            case 4: //staff
                storedProcName = "sp_SFParticipantSearch_staff";
                break;
            case 0: //nothing selected. Could display error here or go with a default storedproc
                storedProcName = "";
                break;  
        }

        if (String.IsNullOrEmpty(storedProcName) == false)
        {
            Response.Write(storedProcName);
            SqlCommand cmd3 = new SqlCommand(storedProcName, myConnection);
            cmd3.CommandType = CommandType.StoredProcedure;
            // Add your parameters here
            cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
            cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"].ToString()));

            myConnection.Open();

            SqlDataReader reader = cmd3.ExecuteReader();

            gridsearch.DataSource = reader;
            gridsearch.DataBind();

            reader.Close();
            myConnection.Close();

        }
        else
        {
            Response.Write("No store Procedures");
        }
    }

    protected void dropdown_change(object sender, EventArgs e)
    {
        Bind_Search();
    }
}

Open in new window

Romacali

ASKER
I did and still nothing :(

I also have a search button
<asp:Button ID="Button1" OnClick="btnSearch_Click" CssClass="form_submit_button"  runat="server" Text="Search"  />



 protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!IsEmpty(txtFileNo.Text))
        {
            Bind_Search();

        }
    }
Rajar Ahmed

hi mate,

If u want to call sp on the button click event then you have to do this code .








<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtFileNo" runat="server"></asp:TextBox>
    <asp:DropDownList runat="server" ID="ddlParticipantType" 
     CssClass="form_input" Width="130px">
    <asp:ListItem Value="0" Text="Select" />
    <asp:ListItem Value="1" Text="Teens" />
    <asp:ListItem Value="2" Text="Adults" />
     <asp:ListItem Value="3" Text="Seniors" />
    <asp:ListItem Value="4" Text="Staff" />
    </asp:DropDownList> 
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="btnSearch_Click" />
                      
     </div>
    </form>
Code behind::

protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtFileNo.Text))
        {
            Bind_Search();

        }
        else
        {
            Response.Write("Please Write Text File Number");
        }
    }

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Romacali

ASKER
it is still not working when I selected the teens on the ddl nothing happens, no matter if I click search or not
Romacali

ASKER
I'm going crazy here
Rajar Ahmed

hi Romacali,

I had corrected the issue which was existed in the switch statement  before, So i moduled such a way the sp will be executed only other than zero .

So this wat Process I think:

First u enter some keywords in textbox,
 then u select dropdown value
 and then click that button

Button Click event Checks Dropdown Value ,
If the value is other than Zero ur storeprocedure will be executed

if its zero then store procedure will not be executed .

This is wat i showed u , in the below Code.

It works PRetty well for me .

Meeran 03 :)



<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtFileNo" runat="server"></asp:TextBox>
    <asp:DropDownList runat="server" ID="ddlParticipantType" 
     CssClass="form_input" Width="130px">
    <asp:ListItem Value="0" Text="Select" />
    <asp:ListItem Value="1" Text="Teens" />
    <asp:ListItem Value="2" Text="Adults" />
     <asp:ListItem Value="3" Text="Seniors" />
    <asp:ListItem Value="4" Text="Staff" />
    </asp:DropDownList> 
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="btnSearch_Click" />
        
                      
     </div>
    </form>
Code behind ::
 private void Bind_Search()
    {
        string storedProcName = string.Empty;
        switch (int.Parse(ddlParticipantType.SelectedValue))
        {
            case 1: //teens 
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults
                storedProcName = "sp_SFParticipantSearch_adult";
                break;
            case 3: //seniors
                storedProcName = "sp_SFParticipantSearch_senior";
                break;
            case 4: //staff
                storedProcName = "sp_SFParticipantSearch_staff";
                break;
            case 0: //nothing selected. Could display error here or go with a default storedproc
                storedProcName = "";
                break;  
        }

        if (String.IsNullOrEmpty(storedProcName) == false)
        {
            Response.Write(storedProcName);
             //SqlCommand cmd3 = new SqlCommand(storedProcName, myConnection);
            //cmd3.CommandType = CommandType.StoredProcedure;
            //// Add your parameters here
            //cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
            //cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"].ToString()));

            //myConnection.Open();

            //SqlDataReader reader = cmd3.ExecuteReader();

            //gridsearch.DataSource = reader;
            //gridsearch.DataBind();

            //reader.Close();
            //myConnection.Close();
        }
        else
        {
            Response.Write("No store Procedures");
        }
    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtFileNo.Text))
        {
            Bind_Search();
           
        }
        else
        {
            Response.Write("Please Write Text File Number");
        }
    }

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
Romacali

ASKER
looks it is calling the procedure but it is not displaying the gridview with the results

aspx:
File No
  <asp:TextBox  CssClass="form_input" ID="txtFileNo" Width="130px" runat="server" />

           
        Type:
 <asp:DropDownList runat="server" ID="ddlParticipantType"  CssClass="form_input" Width="130px">
    <asp:ListItem Value="0" Text="Select" />
    <asp:ListItem Value="1" Text="Teens" />
    <asp:ListItem Value="2" Text="Adults" />
     <asp:ListItem Value="3" Text="Seniors" />
    <asp:ListItem Value="4" Text="Staff" />
    </asp:DropDownList>  

<asp:Button ID="Button1" OnClick="btnSearch_Click" CssClass="form_submit_button"  runat="server" Text="Search"  />
       

        <asp:GridView ID="gridsearch"  AllowPaging="true" PageSize="10"  OnRowCommand="gridsearch_RowCommand"  EmptyDataText="No Participants were found." AutoGenerateColumns="False" runat="server" CellPadding="4" GridLines="None" ForeColor="#333333"  >
        <Columns>
              <asp:BoundField DataField="TeensID"  HeaderText="Teens ID" SortExpression="TeensID" ></asp:BoundField>
              <asp:BoundField DataField="FileNo" HeaderText="File Number" SortExpression="FileNo" ></asp:BoundField>
              <asp:BoundField DataField="Fdate" HeaderText="Date of First Module" SortExpression="Fdate" DataFormatString="{0:MM/dd/yyyy}"></asp:BoundField>
              <asp:TemplateField ShowHeader="False">
           
            <ItemTemplate>
         
         <asp:LinkButton  Text="select" ID="lnkbtnreg" CssClass="Hopelink" runat="server" CommandName="Select" CommandArgument='<%# Bind("TeensID") %>'></asp:LinkButton>

         
                    </ItemTemplate></asp:TemplateField>
 
        </Columns>
            <FooterStyle BackColor="#507CC5" ForeColor="White" Font-Bold="True" />
            <RowStyle BackColor="#F8FAFC" ForeColor="#333333" />
            <PagerStyle BackColor="#ffffff" ForeColor="#284775" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CC5" Font-Bold="True" ForeColor="White" Font-Size="12px" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <EditRowStyle BackColor="#999999" />
       
       
        </asp:GridView>



//CS

  private void Bind_Search()
    {
        string storedProcName = string.Empty;
        switch (int.Parse(ddlParticipantType.SelectedValue))
        {
            case 1 : //teens
                storedProcName = "sp_SFParticipantSearch";
                break;
            case 2: //adults
                storedProcName = "sp_SFParticipantSearch_adult";
                break;
            case 3: //seniors
                storedProcName = "sp_SFParticipantSearch_senior";
                break;
            case 4: //staff
                storedProcName = "sp_SFParticipantSearch_staff";
                break;
            case 0: //nothing selected. Could display error here or go with a default stored proc
                throw new NotImplementedException("No Type selected. Not sure of desired behavior");


                if (String.IsNullOrEmpty(storedProcName) == false)
                {
                    Response.Write(storedProcName);

                }
                else
                {
                    Response.Write("No store Procedures");

                }
                //SqlCommand cmd3 = new SqlCommand("storedProcName", myConnection);
                //cmd3.CommandType = CommandType.StoredProcedure;
                //// Add your parameters here
                //cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
                //cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"].ToString()));

                //myConnection.Open();

                //SqlDataReader reader = cmd3.ExecuteReader();

                //gridsearch.DataSource = reader;
                //gridsearch.DataBind();

                //reader.Close();
                //myConnection.Close();
        }
    }

   protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtFileNo.Text))
        {
            Bind_Search();

        }
        else
        {
            Response.Write("Please Write Text File Number");
        }

    }
Rajar Ahmed

Try to check in sql query analyser , whether u receive data or not ,

This will generate to execute ur storeprocedure with given  parameters , Copy and paste in sql analyser and check whether u retrieve records or not .

Response.Write("exec " + storedProcName + " '" + txtFileNo.Text.Trim() + "','"  + Session["sOrgID"] + "'");    

Like This below,
exec sp_SFParticipantSearch 'test',''          




 if (String.IsNullOrEmpty(storedProcName) == false)
        {
             Response.Write("exec " + storedProcName + " '" + txtFileNo.Text.Trim() + "','"  + Session["sOrgID"] + "'");            
            SqlCommand cmd3 = new SqlCommand(storedProcName, myConnection);
            cmd3.CommandType = CommandType.StoredProcedure;
            // Add your parameters here
            cmd3.Parameters.Add(new SqlParameter("@FileNo", txtFileNo.Text.Trim()));
          
            cmd3.Parameters.Add(new SqlParameter("@OrgID", Session["sOrgID"]));

            myConnection.Open();

            SqlDataReader reader = cmd3.ExecuteReader();

            gridsearch.DataSource = reader;
            gridsearch.DataBind();

            reader.Close();
            myConnection.Close();

        }

Open in new window

Romacali

ASKER
nothing is happenning
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Romacali

ASKER
let me know if you want me to attache the pages
Romacali

ASKER
I added all this on the page load
and I got this error:

 No Type selected. Not sure of desired behavior
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotImplementedException: No Type selected. Not sure of desired behavior

Source Error:

Line 63:             break;
Line 64:         case 0: //nothing selected. Could display error here or go with a default stored proc
Line 65:             throw new NotImplementedException("No Type selected. Not sure of desired behavior");
Line 66:
Line 67:
Rajar Ahmed

hi ,

i had removed this code long before .  
Please attach ur code and storeprocedures . !
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Romacali

ASKER
see attached

thanks
procedure:
*************************/

CREATE  PROCEDURE sp_SFParticipantSearch (  
@FileNo as varchar(50) = null,
@OrgID as int) AS

 
select  TeensID, Fdate, FileNo 
from tbl_SF_Teens
where (@FileNo is null or FileNo Like '%' +@FileNo + '%') and (OrgID = @OrgID)

GO

Open in new window

cs.txt
aspx.txt
Rajar Ahmed

Hi mate ,

Srry for replying late , I was rediculously busy with my work .

Please try the attach code .

Let me know if u face any issue .

I find no issue with ur sp so nothing to worry .

Theres nothing i had changed in aspx page its same as u attached . !!

Meeran 03 : )


dropdowscs.txt
ASKER CERTIFIED SOLUTION
Rajar Ahmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Romacali

ASKER
thanks I will try
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Romacali

ASKER
it is not working