datagrid row color change

G

Ganesh

Hi There,

I've a datagrid in the left hand side menu, depends user selection i
want to highlight the row. It works but if user navigated any page
inside that page then it won't highlight. The pageid is not in the
menu grid.
I try to storing last selected page in the session, then want to
hightlight that menu in the grid. How can i use that.

private void UserMenu_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType ItemType = e.Item.ItemType;
if (ItemType == ListItemType.Item || ItemType ==
ListItemType.AlternatingItem )
{

if (Request.QueryString["Page"] != null)
{
if (Request.QueryString["Page"] == e.Item.Cells[0].Text)
{
TableRow tRow = e.Item;
tRow.CssClass = "Menu_header_Selection";
//Session.Add("LastMenuPage",
Request.QueryString["Page"].ToString());
}

}


}

Thanks
 
M

Mohamad Elarabi [MCPD]

Ideally, if you enableViewState=True on your DataGrid tag you shouldn't have
to do any of this. But if for some strange reason that doesn't work here is
what you could do.

You should consider using the selectedIndex Property of the datagrid. You
should be setting the session variable in the selectedIndexChanged event of
your datagrid. You'd do that by writing something like this

session.Add("LastMenuPage",UserMenu.selectedIndex.toString());

Then you should read and set that back in the PreRender event of your
DataGrid (not of the page). Something like this


UserMenu.selectedIndex = session["LastMenuPage"];

All this does is worry about remembering which item was selected previously.
You shouldn't have to worry about setting the background color in code. You
can do that by setting the SelectedItemStyle-BackColor in the <asp:DataGrid>
tag on the front end, so your tag should look something like this

<asp:DataGrid id="UserMenu" runat="server"
SelectedItemStyle-BackColor="blue" ...>...</asp:DataGrid>

I hope this helps. Let me know. Thanks,
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top