Tuesday, 28 November 2017

Double click on gridview using asp.net

1./////////// HTML

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" AutoGenerateColumns="false"
    OnRowDataBound="GridView1_RowDataBound"  OnRowCommand="GridView1_RowCommand">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
        <asp:CommandField SelectText="Select" ShowSelectButton="true" Visible="false" />
    </Columns>

</asp:GridView>



2.//////////// Event on page directory

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>




3.////////// CS

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("ondblclick", "__doPostBack('GridView1','Select$" + e.Row.RowIndex + "');");
            e.Row.Attributes["style"] = "cursor:pointer;";
        }
    }
  
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow gvRow = GridView1.Rows[index];

    }

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...