[RESOLVED]On link click from menu BindDataList

I have this code:

$(document).ready(function () {


        $('#Priroda').hide();

        $('#priroda_').click(function () {
            $('#Znamenitosti').hide();
            $('#Priroda').show();


        });

        $('#znamenitosti_').click(function () {
            $('#Priroda').hide();
            $('#Znamenitosti').show();
        });
    });


</script>
 <div class="meni">
    <nav>
    <ul>
    <li class="active"><a href="#">Info</a></li>
    <li><a href="#" id="znamenitosti_">Znamenitosti</a></li>
    <li><a href="#" id="priroda_">Priroda</a></li>
    <li><a href="#" id="nokenzivot_">Noken Zivot</a></li>
     </ul>
        </nav>
        </div>

where I have few categories in the menu. When i click on specific category, i want to show the (div) tag for that specific category within the same .aspx page, and the other (div) tags for the other categories should be hidden. This is the (div) tag for the category “Priroda”:

<div class="Priroda" id="Priroda">
         <asp:DataList ID="DataList1" runat="server" RepeatColumns="7" CellPadding="3">
  <ItemTemplate>
<div class="boxButton">
<ul class="Gallery">
<li><a id="A1"  href='<%# Eval("ime","~/Sliki/Ohrid/Priroda/{0}") %>' title='<%# "Од "+ Eval("userid")+ ", на " +  Eval("datum")+ ", " +  Eval("opis")%>'  rel="FaceBox[gallery1]" runat="server" >
 <asp:Image ID="Image1"  ImageUrl='<%# Bind("ime", "~/Sliki/Ohrid/Priroda/{0}") %>' runat="server" Width="140" Height="140" AlternateText='<%# Bind("imeslika") %>' />
 </a></li></ul></div>
 </ItemTemplate>
 </asp:DataList>
    </div>

For binding the DataList i used this code in .cs file:

protected void BindDataList1()
{
    String strConnString = System.Configuration.ConfigurationManager
        .ConnectionStrings["makbazaConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(strConnString);
    con.Open();
    //Query to get ImagesName and Description from database
    SqlCommand command = new SqlCommand("SELECT ime, imeslika, kategorija, datum, opis, slikapateka, userid FROM Ohrid WHERE kategorija='Priroda'", con);
    SqlDataAdapter da = new SqlDataAdapter(command);
    DataTable dt = new DataTable();
    da.Fill(dt);
    dlImages.DataSource = dt;
    dlImages.DataBind();
    con.Close();
}

Now i don’t know how to call BindDataList1(); to show me data when i click on that category. I have different BindDataLists for each category. Can you tell me how to call specific BindDataList for the category that is selected from the menu? For example
when i click on link Priroda show me the (div) tag Priroda and BindDalaList1();, when i click on link Znamenitosti show me the (div) tag Znamenitosti and BindDalaList2();

Hi ,

try this 

<ul> <li><a href="Default2.aspx?ID=2" id="znamenitosti_">Znamenitosti</a></li></ul>

and then 

  protected void BindDataList1()
    {
        String strConnString = System.Configuration.ConfigurationManager
            .ConnectionStrings["makbazaConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        con.Open();
        //Query to get ImagesName and Description from database
        if (Request.QueryString["ID"] != null)
        {
            SqlCommand command = new SqlCommand("SELECT ime, imeslika, kategorija, datum, opis, slikapateka, userid FROM Ohrid WHERE kategorija=" + Request.QueryString["ID"].ToString(), con);
        }
        else
        {
            SqlCommand command = new SqlCommand("SELECT ime, imeslika, kategorija, datum, opis, slikapateka, userid FROM Ohrid WHERE kategorija='Priroda'", con);
        }
            SqlDataAdapter da = new SqlDataAdapter(command);
        DataTable dt = new DataTable();
        da.Fill(dt);
        dlImages.DataSource = dt;
        dlImages.DataBind();
        con.Close();
    }

call finction 

BindDataList1()
on pageload within !ispostback

Leave a Reply