Wednesday, August 8, 2012

Select the Cell values on mouseover in gridview row in asp.net.

OR

Edit row on mouseover in gridview in asp.net.
protected void gridViewName_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string str1 = gridViewName.Rows[index].Cells[0].Text;
                string str2 = gridViewName.Rows[index].Cells[1].Text;
                TextboxName.Text = Convert.ToDateTime(str1).ToString("MM/dd/yyyy");
                TextboxName.Text = str2;
            }
        }


        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            foreach (GridViewRow row in gridViewName.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    row.Attributes["onmouseover"] = "this.style.cursor='hand';";
                    row.Attributes["onmouseout"] =
                       "this.style.textDecoration='none';";
                    row.Attributes["onclick"] =
                     ClientScript.GetPostBackClientHyperlink(gridViewName,
                        "Select$" + row.DataItemIndex, true);
                }
            }
            base.Render(writer);
    
    }

No comments: