Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Needs Help With Multiple Query Strings
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Needs Help With Multiple Query Strings

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Needs Help With Multiple Query Strings
    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.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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> 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.