passing parameter from search form for report
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: passing parameter from search form for report

  1. #1
    Join Date
    Jun 2009
    Posts
    15

    Exclamation passing parameter from search form for report

    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 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






    Code:
    <&#37;
    @ 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();
    }
    
     
    }
    }
    Last edited by Shuja Ali; July 1st, 2009 at 03:41 PM. Reason: added code tags

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: passing parameter from search form for report

    Welcome to this forum.

    First, please use codetags ( [ code] your code here [/ code] , but then without the spaces) to post your code. It is unreadable now and no one will give a try to read such large code as plain text.

    Next, a few questions are not specific to your post 'passing parameter .. for report', like the radio option and selectedIndexChanged. I would suggest to start a seperate thread for these questions.

    Last, try to be more specific.
    I tried "onselectedIndexchange" it give me an error
    What kind of error?

  3. #3
    Join Date
    Jun 2009
    Posts
    15

    Re: passing parameter from search form for report

    thank you
    following is the error
    i get onselected indexchange
    Server Error in '/hits' Application.
    --------------------------------------------------------------------------------

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1061: 'ASP.search_aspx' does not contain a definition for 'ddlCity_SelectedIndexChanged' and no extension method 'ddlCity_SelectedIndexChanged' accepting a first argument of type 'ASP.search_aspx' could be found (are you missing a using directive or an assembly reference?)

    Source Error:



    Line 91: </asp:ObjectDataSource>
    Line 92: CITY:
    Line 93: <aspropDownList ID="ddlCity" runat="server" DataSourceID="SrcCty"
    Line 94: DataTextField="CITY" DataValueField="STATE_COUNTRY_CODE" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged" >
    Line 95: </aspropDownList>


    Source File: c:\hits\Search.aspx Line: 93

    here's the aspx code:
    Code:
    <%@ 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" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged" >
    In c#
    Code:
    protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
            {
    
                sSQL += "AND CITY='" + ddlCity.SelectedValue.ToString() + "'";
                MakeSQL();
            }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center