Hover Menu Control + GridView

In this present code snippet i am giving the code for hovermenu control over the gridview .It will works simply as the pop up control in other words it will gives the tool tip on mouse over

Source code for this is


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowEditing="GridView1_RowEditing" Caption="Customer List" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating" EmptyDataText="You have deleted all records in customer list" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:Panel ID="Panel1" runat="server" Width="400px">
<asp:Label ID="lblCode" runat="server" Text='<%# Eval("Cus_Code") %>' Visible="False"></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Cus_Name") %>'></asp:Label>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Cus_City") %>' ></asp:Label>
</asp:Panel>

<cc1:HoverMenuExtender ID="HoverMenuExtender1" runat="server" HoverCssClass="popupHover" PopupControlID="PopupMenu" TargetControlID="Panel1" PopupPosition="Left"> </cc1:HoverMenuExtender>

<asp:Panel ID="PopupMenu" runat="server" CssClass="popupMenu">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="AddNew" Text="Add New"></asp:LinkButton>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
</asp:Panel>

</ItemTemplate>

<EditItemTemplate>

<asp:Panel ID="Panel1" runat="server" Width="400px">
<asp:Label ID="lblCode" runat="server" Text='<%# Eval("Cus_Code") %>' Visible="false"></asp:Label>
<asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Cus_name") %>'></asp:TextBox>
<asp:TextBox ID="txtCity" runat="server" Text='<%# Eval("Cus_city") %>'></asp:TextBox>
</asp:Panel>

<cc1:HoverMenuExtender ID="HoverMenuExtender2" runat="server" HoverCssClass="popupHover" PopupControlID="PopupMenu" PopupPosition="Right" TargetControlID="Panel1"> </cc1:HoverMenuExtender>

<asp:Panel ID="PopupMenu" runat="server" CssClass="popupMenu" Width="80">
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</asp:Panel>

</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



In BLL write your own function logic in the below functions .Let us consider one class as CustomerCls()::
// Write your own Insert statement blocks



public void Insert(string CustomerName, string Location)
{

}


// Write your own Fetch statement blocks, this method should return a DataTable

public DataTable Fetch()
{

}


// Write your own Update statement blocks.

public void Update(int CustomerCode, string CustomerName, string Location)
{

}

// Write your own Delete statement blocks.


public void Delete(int CustomerCode)
{
}


//Code behind the source
create one new object for that class as shown below

CustomerCls customer=new CustomerCls();

//fetching and filling datagrid ::

private void FillCustomerInGrid()
{
DataTable dtCustomer= customer.Fetch();
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
}



//code to add new records
When Add New option is clicked, the below method gets fired
In the OnRowCommand event of the GridView::

if (e.CommandName.Equals("AddNew"))
{
customer.Insert(null,null);
GridView1.EditIndex = GridView1.Rows.Count;
FillCustomerInGrid ();
}


write this code In the OnRowCommand event of the GridView::

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Do necessary coding to capture customer code, name and location from EditItemTemplate controls
customer.Update(value for customer code, “value for name", “value for location");
GridView1.EditIndex = -1;
FillCustomerInGrid();
}


RowEditing event of the GridView ::

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
FillCustomerInGrid();
}



in RowCancelingEdit::

[coode]
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
FillCustomerInGrid();
}


//Delete

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//Do necessary coding to capture customer code from GridView ItemTemplate section
customer.Delete(value for customer code);
FillCustomerInGrid();
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: