Tuesday, February 5, 2013

Gridview Row Mouseover highlight and anchor link


 protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblDreceive = ((Label)e.Row.FindControl("lblDateReceive"));
            Label lblDissue = ((Label)e.Row.FindControl("lblDateIssue"));

            object d1 = DataBinder.Eval(e.Row.DataItem, "Posted_Purch_Receipt_Date");
            object d2 = DataBinder.Eval(e.Row.DataItem, "Sales_Shipment_Date");
            if (d1 != null)
            {
                DateTime dReceive = DateTime.Parse(d1.ToString());
                lblDreceive.Text = dReceive.Year > 1999 ? dReceive.Day.ToString("00") + "-" + dReceive.Month.ToString("00") + "-" + dReceive.Year.ToString("00") : "";
            }
            else
            {
                lblDreceive.Text = "";
            }

            if (d2 != null)
            {
                DateTime dIssue = DateTime.Parse(d2.ToString());
                lblDissue.Text = dIssue.Year > 1999 ? dIssue.Day.ToString("00") + "-" + dIssue.Month.ToString("00") + "-" + dIssue.Year.ToString("00") : "";
            }
            else
            {
                lblDissue.Text = "";
            }

            string script = String.Format("window.open('./EditBufferExchange.aspx?t=tool&entryno={0}&purrec={1}','_self')", DataBinder.Eval(e.Row.DataItem, "Entry_No"), DataBinder.Eval(e.Row.DataItem, "Posted_Purch_Receipt_No"));
            e.Row.Attributes.Add("onclick", script);

            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#F9E5B6';this.style.cursor='pointer';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff';");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#F9E5B6';this.style.cursor='pointer';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#f1f3f6';");
            }


        }
    }

2 comments:

  1. Hello There. I discovered your weblog the use of msn. This is a
    really smartly written article. I will be sure to bookmark it and come back to learn extra
    of your useful info. Thank you for the post. I will definitely comeback.


    my weblog: Ihre online Parfümerie

    ReplyDelete