Menu Items

S

Seema

I have a web form. Where I have menu items and when in the same page I have a
conten holder where I have to show Grid views. e.g if I click on MenuItem1
it should show GridView1 in the same page. If I click on MenuItem2 it should
show Gridview2 and so on. How can I do that.
 
M

Mark Stevens

Few different things you could look at depending upon the level of
sophistication and complexity and size of data set returned.

Simplest
Postback to the page from the buttons. Populate and make the
appropriate gridview visible.

Whilst this is simple it will cause the browser to refresh the page on
the postback.

AJAX
Put the buttons and gridviews in an update panel and do the same as
the above.

This has the advantage that there is no "flicker". However, you get
the overhead associated with using an update panel.

JavaScript/jQuery
Populate both gridviews on page load and bind some JavaScript to the
menu items.

This has the advantage that their is no reload of the page but you do
have to send all of the data for both gridviews to the user on the
page load. If you have large data sets then performance would be an
issue.

Hope this helps,
Mark

I have a web form. Where I have menu items and when in the same page I have a
conten holder where I have to show Grid views. e.g if I click on MenuItem1
it should show GridView1 in the same page. If I click on MenuItem2 it should
show Gridview2 and so on. How can I do that.
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)

This message is provided "as is".
 
G

Guest

I have a web form.  Where I have menu items and when in the same page I have a
conten holder where I have to show Grid views.  e.g if I click on MenuItem1
it should show GridView1 in the same page.  If I click on MenuItem2 it should
show Gridview2 and so on.  How can I do that.

Put Menu control, GridView1, and GridView2 on your page. Create menu
items, e.g.

<asp:Menu ID="Menu1" runat="server"
onmenuitemclick="Menu1_MenuItemClick">
<Items>
<asp:MenuItem Text="MenuItem1" Value="MenuItem1">
</asp:MenuItem>
<asp:MenuItem Text="MenuItem2" Value="MenuItem2">
</asp:MenuItem>
</Items>
</asp:Menu>

A method named Menu1_MenuItemClick will be created for you in the code-
behind file for the page, add there following code

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
switch (e.Item.Value)
{
case "MenuItem1":
GridView1.Visible = true;
GridView2.Visible = false;
return;
case "MenuItem2":
GridView1.Visible = false;
GridView2.Visible = true;
return;
}
}

To show initially just one grid, add to the Page_Load method following
code:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.Visible = true;
GridView2.Visible = false;
}
}

Hope this helps
 
S

Seema

Thanks a lot. It is very useful information. But in my case I have around
25 different Gridviews and 25 menuitems. Is this methods works with that.
 
G

Guest

Thanks a lot.  It is very useful information.  But in my case I have around
25 different Gridviews and 25 menuitems.  Is this methods works with that.

I am not sure if you really need to have 25 different gridviews on the
same form. Did you try to use just one gridview and programmatically
set its datasource?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top