C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Hover Menu Control + GridView


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: AJAX
Author: komaladeviMember Level: Gold    
Rating: Points: 10



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();
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Solution for Dropdownlist or List to fit the lenghty items. (ASP.NET)
Previous Resource: How to use Model Popup Extender
Return to Discussion Resource Index
Post New Resource
Category: AJAX


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use