Click here to Skip to main content
15,122,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am building an website. I am new to this IT world.
I have a list view which contains a image and a label of the Category. I am wrapped these items in tag, so that whenever the user click in any of these controls it will redirect to another page. Outside the list view i have an ajax combo box which contains city names. It has a selected value on page load.
Now whenever a user clicks on either image or label inside list view it will redirect to page SubCat.aspx with query string values containing city and category name.
This query string will be passed in "a href="page?query string""

My problem is that i am not able to get the combo box value in a tag in aspx page. I know how to pass query string from code behind.

or is there anyway to put the values of querystring or form the query string in aspx.cs page and then retrieve it in "a" tag in aspx page?

Thank you.

code of aspx:

    $( document ).ready(function() {
    var _cityId = $('#ComboBox1').val();
    var url = "" + _cityId;
    $( "span" ).on( "click", function() {
        window.location.href = url;


 <asp:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="SuggestAppend" DataSourceID="SqlDataSource1"
                                            DataTextField="city" AutoPostBack="True" DataValueField="city" OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged"
                                            MaxLength="0" Style="display: inline;">
                                            <asp:ListItem>---Select City---</asp:ListItem>

<asp:ListView ID="ListView1" GroupItemCount="3" GroupPlaceholderID="ContactRowContainer"
                                    ItemPlaceholderID="ContactItemContainer" runat="server">
                                        <table cellpadding="50" width="600px" runat="server" id="tblContacts">
                                            <tr id="Tr1" runat="server">
                                            <tr runat="server" id="ContactRowContainer" />
                                        <br />
                                        <tr runat="server" id="ContactRow">
                                            <td runat="server" id="ContactItemContainer" />
                                        <td runat="server" id="Td1" align="center">
                                         <%--   <a href="User/SubCat.aspx?cid=<%#Eval("cat_name") %>">--%>
                                                <asp:Image ID="Image1" runat="server" Width="100" Height="100" ImageUrl='<%#Eval("image") %>' />
                                                <asp:Label ID="Label1" runat="server" Text='<%#Eval("cat_name") %>'></asp:Label></span>

Updated 11-Aug-14 1:58am
Trung Nguyen Son 11-Aug-14 6:57am
I've cleared all other answers, which are not close enough to your question.
Check this below solution out!
Trung Nguyen Son 11-Aug-14 7:09am
Please check out the solution 4.
I've made it success!

1 solution

Please follow this step:
1. Add this link in Head tag:
<script src="//"></script>

2. Assume your HTML like this:
<asp:dropdownlist id="ComboBox1" runat="server">
        <asp:listitem value="1">Hanoi</asp:listitem>
        <asp:listitem value="2">HCM City</asp:listitem>

   <a href="User/SubCat.aspx?cid=wer">Redirect</a>

3. The script to get value in Combobox 1 then append param to href of the <a> tag below:
        $(document).ready(function () {
            var _cityId = $('#<%= ComboBox1.ClientID %>').val();
            $("a").each(function () {
                $(this).prop('href', $(this).attr('href') + '&cityid=' + _cityId);
Ashi0891 11-Aug-14 8:01am
I am afraid it didnt help me any :(
Trung Nguyen Son 11-Aug-14 9:11am
There may be some missunderstandings!
I think you should post your full code (including aspx file and code behind) anh make clear the requirement. Then I will give it a try!
I find it not quite difficult to solve your problem!
Ashi0891 14-Aug-14 5:04am
sorry I got busy with my other projects. Thank you for your solution.

replacing var _cityId = $('#<%= ComboBox1.ClientID %>').val();
with var _cityId = $("<%= ComboBox1.ClientID %>").val();
in your given code, solved my problem :)
Ashi0891 19-Aug-14 5:07am
hey I am still not getting my required result. It doesnt show anything in cityid. Its empty.
Trung Nguyen Son 20-Aug-14 6:54am
Pleas post your code, I will take a look!
Ashi0891 20-Aug-14 6:56am
<script type="text/javascript">

$(document).ready(function () {
//get the selected value
var _cityId = $("#ComboBox1 option:selected").text();
$(".cid").each(function () {
$(this).prop('href', $(this).attr('href') + '&cityid=' + _cityId);
Trung Nguyen Son 20-Aug-14 21:37pm
Your usage is wrong:
#<%= ComboBox1.ClientID %> option:selected....
Ashi0891 22-Aug-14 7:20am
even this doesnt work for me.
Trung Nguyen Son 22-Aug-14 10:50am
Post your code, I will check for u.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900