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();
}
}
<%@ 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();
}
}
<%@ 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();
}
}
<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");
}
}
<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");
}
}
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