datagrid row color change

datagrid row color change

am 28.12.2007 10:50:47 von 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

RE: datagrid row color change

am 28.12.2007 12:05:01 von MohamadElarabiMCPD

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
tag on the front end, so your tag should look something like this

SelectedItemStyle-BackColor="blue" ...>...

I hope this helps. Let me know. Thanks,

--
Mohamad Elarabi
MCP, MCTS, MCPD.


"Ganesh" wrote:

> 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
>