.

Gridview Databinding

The following is a simple and good solution for a roll over bar for gridviews.
No postbacks are done this way – only javascript redirection: 

 

 

List<string> EventsToRegister = new List<string>();
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.originalcolor=this.style.backgroundColor; this.style.backgroundColor='#B5B5FF'; this.style.cursor='pointer';");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor; this.style.cursor='default';");
        EventsToRegister.Add(GridView1.UniqueID);
    }
}
protected override void Render(HtmlTextWriter writer)
{
    foreach(GridViewRow gvr in GridView1.Rows)
        if (gvr.RowType == DataControlRowType.DataRow)
        {
            string s = Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + gvr.RowIndex.ToString(), true);
            this.Page.ClientScript.RegisterForEventValidation(s);
            gvr.Attributes.Add("onclick", s);
        }
    base.Render(writer);
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
}

 

 

also can use the following code in the gridview source:

 

<asp:templatefield>
<itemtemplate>
    <asp:linkbutton ID="LinkbuttonSelect" runat="server" commandname="Select"  CommandArgument= '<%# Eval ( "ID" ) %>' text="Select"  BackColor="AliceBlue"/>
</itemtemplate>
</asp:templatefield>

 

in conjunction with:

 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
      Guid index = new Guid(e.CommandArgument.ToString());  // just an example - in this case the command argument was a GUID

What's your thoughts on this?

*

Protected by WP Anti Spam