Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

datagrid row color change

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ganesh - 28 Dec 2007 09:50 GMT
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
Mohamad Elarabi [MCPD] - 28 Dec 2007 11:05 GMT
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,

Signature

Mohamad Elarabi
MCP, MCTS, MCPD.

> Hi There,
>
[quoted text clipped - 28 lines]
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.