Click here to Skip to main content
15,889,840 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In my project i have a navigation bar which shows the different types of recipes e.g: Healthy Recipes, Desserts, etc...

In the same page i have a gridview which is binded by database (RecipeTable) to show the list of recipes available.

My problem is how should i bind gridview with the navigation bar selection.

e.g: when a user clicks on Healthy Recipe the gridview should show the recipes saved under healthy recipes type.

i have search a lot but could not find anything related to this.

Please help me.
Posted
Comments
Mahesh_Bhosale 28-Mar-14 4:37am    
you need to get id of recipes from navigation bar. and then pull data form database upon id.
Garishma 28-Mar-14 4:41am    
Could you please explain in detail.. m a newbie. just a small example. please

onclick event for navigation bar, and in onclick event you sort the data table based on your id of the clicked navigartion bar and bind the grid..


example : I have datatable in session,

I clicked on "Link1"

then in onclick event

if(id="Link1")
{
datatable.sort("your condition")
gridview.datasource=datatable;
gridview.bind();
}
else if(id="Link2")
{
C#
datatable.sort("your condition")
gridview.datasource=datatable;
gridview.bind();


}
 
Share this answer
 
Comments
Garishma 28-Mar-14 4:58am    
<div id="naviRecipe">
<ul>
<li>Healthy Recipes</li>
<li>Desserts</li>
</ul>
</div>

this is my code for navigation. what should i mention in tag???
It depends what sort of navigation bar do you use.
If your navigational control is html then add runat="server" attribute to its tag and on code behind you add something like this:
C#
protected void Page_Load(object sender, EventArgs e)
{
     if (!this.IsPostBack)
     {
         this.yourNavigationControl.ServerClick += (s, evt) =>
         {
          //Bind data to your grid according to navigation element you have clicked
         };
    }
}


If your navigation control is WebForms control, then it is even simpler.
Most controls (if not all) used for navigation have some sort of click event - use that!
C#
protected void NavigationButton_Click(object sender, EventArgs e)
{
     //Bind data to your grid according to navigation element you have clicked
}

protected void MenuItemClick(object sender, MenuEventArgs e)
{
     //Bind data to your grid according to navigation element you have clicked
}
 
Share this answer
 
v2
Comments
Garishma 28-Mar-14 5:24am    
Following is the code used. please help me.

for navigation:
<asp:Menu ID="Menu1" runat="server" OnMenuItemClick="Menu_Click">
<items>
<asp:MenuItem Text="Healthy Recipes">
<asp:MenuItem Text="Desserts">



for binding data:
con.Open();
SqlCommand cmd = new SqlCommand("Select * from RecipeTable where ___________", con);
cmd.ExecuteNonQuery();

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

gridRecipe.DataSource = ds;
gridRecipe.DataBind();
con.Close();
Oshtri Deka 28-Mar-14 6:12am    
C'mon, try harder!
This isn't quantum physics.
The solution is:

My Menu Item Code is:
C#
<asp:Menu ID="Menu1" runat="server" OnMenuItemClick="Menu_Click">
<Items>
    <asp:MenuItem Text="Heathy" Value="0" Selected="true"></asp:MenuItem>
    <asp:MenuItem Text="Kids" Value="1"></asp:MenuItem>
</Items>
</asp:Menu>


MenuItem_Click code is:

C#
string MenuBind = Menu1.SelectedItem.Text;
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["aaaaaaaaaaaa"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from [tablename] WHERE column_name=@type", con);
        cmd.Parameters.Add(new SqlParameter("@type", MenuBind));
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        gridRecipe.DataSource = ds;
        gridRecipe.DataBind();
        con.Close();


Thanks a lot for your attention.. Appreciated!!!!
 
Share this answer
 

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