Print Page | Close Window

Needs Help With Multiple Query Strings

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=16457
Printed Date: 29 March 2026 at 4:24am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Needs Help With Multiple Query Strings
Posted By: Misty
Subject: Needs Help With Multiple Query Strings
Date Posted: 06 September 2005 at 1:24pm

Can someone please help me with the bolded parts of the code below? I'd like to add another querystring value to BusinessInfo.aspx. I'd like for it to be something like BusinessInfo.aspx?ID=2&CatID=4. I already have the ID set up. But I'd like to be able to retrieve the CatID (see the code for the data list) and put it as a value for the second query string. The CatID comes from a query string on the previous web page. I have an idea of how to do this in Classic ASP, but I'm not sure how you would do this with a data list in ASP.Net.

 <form runat="server">
            <asp:datalist ID="dtlCity" runat="server"
        Width=500
        RepeatColumns=4
        enableviewcounty=false>
              <itemtemplate>
                <table cellpadding=2>
                &nbs p; <!--DWLayoutTable-->
                &nbs p; <tr>
                &nbs p;   <td height="6"></td>
                &nbs p;   <td width="1"></td>
                &nbs p; </tr>
                &nbs p; <tr valign="top">
                &nbs p;   <td> <a href='<%# DataBinder.Eval (Container.DataItem, "CityID", "BusinessInfo.aspx?ID={0}") %>'>
                &nbs p;     <font color="#660099" size="2" face="Arial, Helvetica, sans-serif">
                &nbs p;     <%# DataBinder.Eval (Container.DataItem, "City") %>
                &nbs p;     </font> </a> </td>
                &nbs p;   <td></td>
                &nbs p; </tr>
                </table>
              </itemtemplate>
            </asp:datalist>
          </form></td>

Code for DataList:

Sub BindCityList()

             Dim strConnect As String
             Dim Conn As New System.Data.SqlClient.SQLConnection
             Dim objCommand As New System.Data.SqlClient.SQLCommand
             Dim strSQL as String
             Dim dtaCity As New System.Data.SqlClient.SQLDataAdapter()
             Dim dtsCity As New DataSet()
             Dim strSubCategory As String
            
                'Get connection string from Web.Config
                strConnect = ConfigurationSettings.AppSettings("ConnectionString")

                Conn = New System.Data.SqlClient.SQLConnection(strConnect)
 
    
             Conn.Open()
   
    'Get incoming querystring values
             strSubCategory = request.params("CatID")

        'Start SQL statement
        strSQL = "select * from City Order By City asc"


        'Set the Command Object properties
        objCommand.Connection = Conn
        objCommand.CommandType = CommandType.Text
        objCommand.CommandText = strSQL

        'Create a new DataAdapter object
        dtaCity.SelectCommand = objCommand

        'Get the data from the database and
        'put it into a DataTable object named dttCity in the DataSet object
        dtaCity.Fill(dtsCity, "dttCity")

        'Set the DataSource property of the DataGrid
        dtlCity.DataSource = dtsCity

        'Bind all the controls on the page
        dtlCity.DataBind()
       
      
        objCommand.ExecuteNonQuery()
       
        'this is the way to close commands
        objCommand.Connection.Close()
       
        Conn.Close()

End Sub

 
I tried doing the following: <a href='<%# String.Format("Businessinfo.aspx?id={0}&catId={1}",DataBinder.Eval (Container.DataItem, "CityID"),  request.params("CatID")) %>'> , but it doesn't show up on the web page at all. There's no error message. The links just don't show up anymore.



Replies:
Posted By: Misty
Date Posted: 07 September 2005 at 1:44pm

I resolved this problem by using a Function. Here's the function that I used:
  Function SetURL(strCityID as String) as String

  Dim strCatID as String 

      If Not request.params("CatID") Is Nothing Then
            strCatID = request.params("CatID").ToString
      
      Return String.Format("Businessinfo.aspx?id={0}&catId={1}",strCityID, strCatID)
   End If

   Return String.Empty
End Function

For the link in datalist, I used the following code:
<td> <a href='<%# SetURL(DataBinder.Eval(Container.DataItem,"CityID").ToString()) %>'>
                &nbs p;    <font color="#660099" size="2" face="Arial, Helvetica, sans-serif">
                &nbs p;     <%# DataBinder.Eval (Container.DataItem, "City") %>
                &nbs p;     </font> </a></td> 



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net