search from to pass parameter for report

Jul 1, 2009 at 10:30 AM

I need to prepare a serch form for  report
What would be the best way to capture parameters in where clause ( I make a ssql()) and everytime user select ssql should change accordingly.
Pl. help me for following:-

1) When user select Radio option  "A" message doesn't show up; and there are no source_year related to "A" but control doesn't work.I tried databind but doesn't work.
 I need to refresh entire form as soon as user change any radio option (how can i do that)
2) I need to correct the logic for ddlyr and ddlToyr--something like
 a) fm yr. should be less than Toyr.
3) sSQL doesn'tshow  From year and Toyear  as soon as I select State.
4)how I can have CIty selected based upon user selected state--I tried "onselectedIndexchange" it give me an error --Pl. help

 

 

 

<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="~/Search.aspx.cs" Inherits="HITS.Search" MasterPageFile="~/hits_main.master"%>
<
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="scMgr" runat="server"/>
<
div>
<
asp:UpdatePanel ID="UP1" runat="server" >
<ContentTemplate>
</ContentTemplate>
</
asp:UpdatePanel>
<table cellspacing="10" border=".02">
<tr>
<td align="left" >
<asp:RadioButtonList ID="RBl1" runat="server" AutoPostBack="True"
CellPadding="2" CellSpacing="5"
onselectedindexchanged="RBl1_SelectedIndexChanged">
<asp:ListItem Value="G" Selected="True" >Regular Grants</asp:ListItem>
<asp:ListItem Value ="A">ARRA Grants</asp:ListItem>
<asp:ListItem Value ="C">Contract</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:ObjectDataSource ID="Srcfmyr" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="HITS.App_code.stateTableAdapters.SOURCE_YEAR_VWTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="RBl1" Name="myType"
PropertyName="SelectedValue" Type="String" DefaultValue="G" />
</SelectParameters>
</asp:ObjectDataSource>
From:
<asp:DropDownList ID="ddlyr" runat="server" AppendDataBoundItems="true"
AutoPostBack="True" DataSourceID="Srcfmyr" DataTextField="SOURCE_YEAR"
DataValueField="SOURCE_YEAR" Font-Underline="False"
onselectedindexchanged="ddlyr_SelectedIndexChanged" >
<asp:ListItem Text="Year" Selected="True" Value="0"></asp:ListItem>
</asp:DropDownList>&nbsp; &nbsp; &nbsp;
<asp:ObjectDataSource ID="SrcToyr" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="HITS.App_code.stateTableAdapters.SOURCE_YEAR_VWTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="RBl1" DefaultValue="G" Name="myType"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:Label ID="lblTo" runat ="server" Text="To:"></asp:Label>
<asp:DropDownList ID="ddlTo" runat="server" AppendDataBoundItems="true"
AutoPostBack="True" DataSourceID="Srcfmyr" DataTextField="SOURCE_YEAR"
DataValueField="SOURCE_YEAR" Font-Underline="False" OnSelectedIndexChanged="ddlTo_Clicked" >
<asp:ListItem Text="Year" Selected="True" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2" align="left" valign="middle">
<br /> <br/>
STATE:
<asp:DropDownList ID="ddlSt" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="STATE_COUNTRY_NAME"
DataValueField="STATE_COUNTRY_CODE" AutoPostBack="True"
onselectedindexchanged="ddlSt_SelectedIndexChanged">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="stateTableAdapters.STATE_COUNTRYTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="ddlyr" Name="FromYear"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="ddlTo" Name="ToYear"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="RBl1" Name="mytype"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="SrcCty" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="stateTableAdapters.CityTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSt" Name="mystatecode"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="RBl1" Name="mytype"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlyr" Name="FromYear"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="ddlTo" Name="ToYear"
PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:ObjectDataSource>
CITY:
<asp:DropDownList ID="ddlCity" runat="server" DataSourceID="SrcCty"
DataTextField="CITY" DataValueField="STATE_COUNTRY_CODE" >
</asp:DropDownList>


</table>
<
hr />
<asp:Label ID="mesg" runat="server" Text="" ForeColor="Red"></asp:Label>
<asp:Label ID="Lbl1" runat="server" ForeColor="Blue"></asp:Label>
<asp:Label ID="lblmsg" runat='server' ForeColor="Red"></asp:Label>
br /><br /><br />
<asp:Button ID="submit" runat="server" Text="Submit"/>
&nbsp; &nbsp;
<asp:Button ID="clear" OnClick="Clear_click" runat="server" Text="Clear"/>
</div>
 
</asp:Content>
 
 
 
 
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using
System.Collections.Specialized;
using
AjaxControlToolkit;
using
System.Configuration;
using
System.Data.OracleClient;
using
System.ComponentModel;
namespace
HITS
{
public partial class Search : System.Web.UI.Page
{
string sSQL = " ";
protected void Page_Load(object sender, EventArgs e)
{
MakeSQL();
}
protected void Clear_click(object sender, EventArgs e)
{
Response.Redirect(
"~/search.aspx");
}
protected void RBl1_SelectedIndexChanged(object sender, EventArgs e)
{
string rectype = RBl1.SelectedValue.ToString();
Int16 fmyr = Convert.ToInt16(ddlyr.SelectedValue);
 
if (rectype == "A")
{
mesg.Text =
"ARRA NOT Available";
}
if (rectype == "C" && fmyr > 2000)
{
mesg.Text =
"No Contracts After 2000";
}
else
MakeSQL();
}
public void MakeSQL()
{
sSQL +=
"AND RECORD_TYPE ='" + RBl1.SelectedValue.ToString() + "'";
Lbl1.Text = sSQL;
}
protected void ddlyr_SelectedIndexChanged(object sender, EventArgs e)
{
string rectype = RBl1.SelectedValue.ToString();
Int16 fmyr = Convert.ToInt16(ddlyr.SelectedValue);
if (rectype == "C" && fmyr > 2000)
{
mesg.Text =
"No Contracts After 2000";
}
else
// RBl1.DataBind();
sSQL +=
"AND SOURCE_YEAR ='" + ddlyr.SelectedItem.ToString() + "'";
MakeSQL();
 
}
protected void ddlTo_Clicked(object sender, EventArgs e)
{
string sSQLfy = "";
string toval = ddlTo.SelectedItem.ToString();
string fmval = ddlyr.SelectedItem.ToString();
if (ddlTo.SelectedIndex >0)
{
int fmyr = int.Parse(ddlyr.SelectedItem.Text);
int toyr = int.Parse(ddlTo.SelectedItem.Text);
if(toyr<= fmyr)
{
ddlTo.ClearSelection();
}
else
sSQLfy =
"AND SOURCE_YEAR between '" + toval + "' AND '" + fmval + "'";
sSQL =sSQLfy.ToString();
MakeSQL();
}
 
}
protected void ddlCongDistt_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ddlSt_SelectedIndexChanged(object sender, EventArgs e)
{
//select State
// ddlSt.DataBind();
sSQL +=
"AND STATE_COUNTRY_CODE='" + ddlSt.SelectedValue.ToString() + "'";
MakeSQL();
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
sSQL +=
"AND CITY='" + ddlCity.SelectedValue.ToString() + "'";
MakeSQL();
}

 
}
}