Nested grid edit doesn't work - c#

I'm stuck on this problem where I have grid within grid where the nested grid is editable. I can't get the edit working. What's complicates things is that the nested grid is inside a modal popup extender.
It works to the point where I click on the edit button. Then the EmptyDataText property kicks in with the message. If I click on it second time the grid opens in edit mode but the update/cancel buttons don't work. The cancel button when click displays the EmptyDataText property.
Another issue is that this nested grid doesn't use a object data source so I'm going to have to all the updating and deleting in the code file. Not sure now to do that either.
I would like some advice as to how to make this corrected. Here is the code:
<asp:GridView ID="gvForum" runat="server" DataSourceID="odsForumApproval" DataKeyNames="id" Width="200px"
RepeatColumns="1" DataKeyField="id" CssClass="gridview"
AutoGenerateColumns="False" GridLines="None" OnSelectedIndexChanged="_OnCommand">
<AlternatingRowStyle CssClass="altbgcolor" />
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:Label runat="server" ID="lblTitle" Text='<%# Bind("Title") %>' />
<asp:Panel id="div" runat="server" align="center" class="confirm" style="display:none" >
<asp:GridView runat="server" ID="gvForumDetail" AutoGenerateColumns="False" DataKeyNames="id"
AllowPaging='true' CssClass="gridview"
AllowSorting="true" PageSize="5" CellPadding="5" OnRowEditing="gvForumDetail_OnRowEditing"
OnRowCancelingEdit="gvForumDetail_CancelRecord" >
<AlternatingRowStyle CssClass="altbgcolor" />
<RowStyle VerticalAlign="Top" HorizontalAlign="Left" />
<HeaderStyle CssClass="greenbar" ForeColor="White" /> <Columns>
<asp:BoundField DataField="id" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:Label runat="server" ID="lblTraining" Text='<%# Bind("title") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtTraining" Text='<%# Bind("title") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Post Message">
<ItemTemplate>
<asp:Label runat="server" ID="lblCompletionDate" Width="250" Text='<%# Bind("description") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtDescription" Text='<%# Bind("description") %>' TextMode="MultiLine" Rows="5" Width="250" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Posted By">
<ItemTemplate>
<asp:Label runat="server" ID="lblRecurence" Text='<%# Bind("MemberName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Posted Date">
<ItemTemplate>
<asp:Label runat="server" ID="lblNotes" Text='<%# Eval("itemdate", "{0:d}") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox runat="server" ID="cbxApproved" Text='<%# Bind("approved") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowCancelButton="true" ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
<br />
<Club:RolloverLink ID="btnClose" runat="server" Text="Close" />
</asp:Panel>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="lblTitle"
PopupControlID="div"
CancelControlID="btnClose"
BackgroundCssClass="modalBackground" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
</Columns>
Code behind:
public void _OnCommand(object sender, EventArgs e)
{
ObjectDataSource ods = new ObjectDataSource();
ods.ID = "ods_ForumDetail";
ods.EnableViewState = true;
ods.TypeName = "ForumApproval";
ods.SelectMethod = "GetForumById";
string id = "";
int rowIndex = gvForum.SelectedIndex;
id = gvForum.DataKeys[rowIndex].Value.ToString();
ods.SelectParameters.Add("id", System.TypeCode.Int32, id);
var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
ModalPopupExtender1.Show();
var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
gvForumDetail.DataSource = ods;
gvForumDetail.DataBind();
}
protected void gvForumDetail_OnRowEditing(Object sender, GridViewEditEventArgs e)
{
var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
ModalPopupExtender1.Show();
var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
gvForumDetail.EditIndex = e.NewEditIndex;
gvForumDetail.DataBind();
}
protected void gvForumDetail_CancelRecord(object sender, GridViewCancelEditEventArgs e)
{
var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
ModalPopupExtender1.Show();
var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
gvForumDetail.EditIndex = -1;
gvForumDetail.DataBind();
}

I will try to answer part of your question, updating and deleting the code. you need to take advantage of the "onrowcommand" for the inner gridview (OnRowCommand).

Related

How to use Ajax Calendar in Grid View to disable past date

I use a CalendarExtender of AjaxControlToolkit in a GridView and a TextBox. And from that TextBox I want to disable future dates.
I am trying below code
<asp:GridView ID="Gridview2" runat="server" AutoGenerateColumns="false" DataKeyNames="Sno" ShowFooter="true" OnRowCommand="Gridview2_RowCommand" CssClass="table table-bordered table-striped"
OnRowCancelingEdit="Gridview2_RowCancelingEdit" OnRowDeleting="Gridview2_RowDeleting" OnRowEditing="Gridview2_RowEditing" OnRowUpdating="Gridview2_RowUpdating" OnRowDataBound="Gridview2_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Sno" Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_sno1" runat="server" Text='<%#Eval("Sno") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date of visit" ShowHeader="false">
<EditItemTemplate>
<asp:TextBox ID="Txt_update_DateofVisit1" runat="server" Text='<%# Eval("DateofVisit","{0:MM/dd/yyyy}") %>' CssClass="form-control"/>
<cc1:CalendarExtender ID="CalendarExtenderedit11" CssClass="Calendar" TargetControlID="Txt_update_DateofVisit1" Format="MM/dd/yyyy" runat="server"></cc1:CalendarExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_DateofVisit1" runat="server" Text='<%# Eval("DateofVisit","{0:MM/dd/yyyy}") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_DateofVisit_add" runat="server" CssClass="form-control" />
<cc1:CalendarExtender ID="CalendarExtendere21" CssClass="Calendar" TargetControlID="txt_DateofVisit_add" Format="MM/dd/yyyy" runat="server"></cc1:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgbtnDelete_add" runat="server" CommandName="Delete" ImageUrl="~/img/grid_delete.png" Text="Edit" ToolTip="click here to delete" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="imgbtnAdd_add" runat="server" CommandName="AddNew" ImageUrl="~/img/grid_add.png" ToolTip="click here to add" CausesValidation="true" ValidationGroup="outadd" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Below is my RowDataBound
protected void Gridview2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
AjaxControlToolkit.CalendarExtender CalendarExtendere21 = (AjaxControlToolkit.CalendarExtender)Gridview2.FooterRow.FindControl("CalendarExtendere21");
CalendarExtendere21.EndDate = DateTime.Now;
// CalendarExtendere21.StartDate = DateTime.Now;
}
}
I get below error:
Object reference not set to an instance of an object.
just use parameter e to find out control in grid
if (e.Row.RowType == DataControlRowType.Footer)
{
AjaxControlToolkit.CalendarExtender CalendarExtendere21 =
(e.Row.FindControl("CalendarExtendere21") as AjaxControlToolkit.CalendarExtender);
}
and don't forget to check for null

asp:gridview textbox old value is post back

<asp:GridView Width="300px" RowStyle-Height="20px" HeaderStyle-Height="25px" DataKeyNames="Id" ID="bankAccounts_List" CssClass="table" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Sorting Handle" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<span class="handle"><img src="../Images/sortingHandler.jpg" height="10" /></span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Account Number">
<ItemTemplate>
<asp:TextBox ID="grd_txtbankAccountNumber" Width="150" onblur="return OnBlurGridTextbox(this);" BorderStyle="None" BackColor="White" style="text-align:left;" runat="server" Text='<%# Eval("AccountNo") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Priority" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:TextBox ID="grd_txtPriority" Width="100" BorderStyle="None" BackColor="White" runat="server" style="text-align:center"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:LinkButton runat="server" ID="grd_linkbutton" OnClientClick="return EditGridButton(this)">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id" >
<HeaderStyle CssClass="hiddencol" />
<ItemStyle CssClass="hiddencol" />
<ItemTemplate>
<asp:Label ID="grd_lblId" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnSaveBankInformation" runat="server" Text="<%$Resources:Strings,save%>"
OnClick="btnSaveBankInformation_Click" />
protected void btnSaveBankInformation_Click(object sender, EventArgs e)
{
TextBox txtBankAccountNumber = bankAccounts_List.Rows[i].Cells[GetColumnIndexByName(bankAccounts_List.Rows[i], "Account Number")].FindControl("grd_txtbankAccountNumber") as TextBox;
}
What ever I change in any of the textbox, On save button I always gets the old binded textbox value not the New value I just entered.
Kindly Help me. and yes i am not binding GridView on PostBack again using !IsPostBack
if (!IsPostBack) //Bind grid only when IsPostBack is false
{
grd.DataSource = //data source ;
grd.DataBind(); // bind data
}

I have a group of radio button in each row of the gridview. Base on the user selection of the radio button, I would like to update the database

I have a group of radio button in each row of the gridview. Base on the user selection of the radio button, I would like to update the database, when user click the Submit Button on the page. How do I reference those radio button in the code page?
source code
<asp:GridView ID="gvActList" runat="server" Font-Size="Smaller" Width="100%" CssClass="tableStyle"
EmptyDataText="No Data Found" AllowPaging="false"
CellPadding="4" AutoGenerateColumns="False" autopostback="true">
<FooterStyle Font-Bold="True" CssClass="tablefooter" />
<RowStyle CssClass="tableRow1" />
<SelectedRowStyle Font-Bold="True" CssClass="tableRowHighlight" />
<HeaderStyle Font-Bold="True" CssClass="tableHeader" Font-Size="9px" />
<Columns>
<asp:TemplateField HeaderText="TM Activity Code" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%" HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_Activity_Code" runat="server" Visible="true" Text='<%# Bind("ACTIVITY_CODE") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="19%" HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_ACTDESC" runat="server" Text='<%# Bind("ACTIVITY_DESC") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User Details" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_User_Details" runat="server" Text='<%# Bind("CREATED_BY") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_PROMO_TYPE" runat="server" Text='<%# Bind("PROMO_TYPE") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCatgDescription" runat="server" Text='<%# Bind("CATEGORY_CODE") %>'
Visible="true"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Range" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblACTIVEFROM" runat="server" Text='<%# Bind("ACTIVE_FROM") %>' Visible="true"></asp:Label>  To  
<asp:Label ID="lblACTIVETO" runat="server" Text='<%# Bind("ACTIVE_TO") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Activity Type" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_Actvity_Type" runat="server" Text='<%# Bind("ACTIVITY_TYPE") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Status" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_Current_Status" runat="server" Text='<%# Bind("status") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View Details" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<itemstyle width="5%" />
<asp:LinkButton CssClass="l_link" Text="View" ID="lnkView" runat="server" ToolTip="View" /></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:Label ID="lblCap" Text="Confirm" runat="server"></asp:Label></HeaderTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<itemstyle width="1%" font-size="2px" horizontalalign="Center" />
<table style="text-align: Center; vertical-align: text-top;">
<tr>
<td style="width: 98%;">
<asp:RadioButton ID="rdYes" runat="server" Text="Yes" GroupName="CH"></asp:RadioButton></td>
</tr>
<tr>
<td style="width: 98%;">
<asp:RadioButton ID="rdNo" runat="server" Text="No" GroupName="CH"></asp:RadioButton></td>
</tr>
<tr>
<td style="width: 98%;">
<asp:RadioButton ID="rdNone" runat="server" Text="None" GroupName="CH"></asp:RadioButton></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle CssClass="tableRowHighlight" />
<RowStyle CssClass="odd_tb" />
<PagerStyle CssClass="foot_tbl" />
<AlternatingRowStyle CssClass="even_tb" />
<PagerSettings Mode="NextPreviousFirstLast" />
</asp:GridView>
pls help me
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (gvActList.Rows.Count > 0)
{
foreach (GridViewRow row in gvActList.Rows)
{
RadioButton rdYes= (RadioButton)row.FindControl("rdYes");
RadioButton rdNo = (RadioButton)row.FindControl("rdNo");
RadioButton rdNone = (RadioButton)row.FindControl("rdNone");
if (rdYes != null && rdNo != null && rdNone != null)
{
if (rdYes.Checked == true)
{
//some code
}
else if (rdNo.Checked == true)
{
//some code
}
}
}
}
}
You can use above code on the button click. One suggestion is to use RadiobuttonList instead of RadioButton so that it will reduce the code.
on button click declare a gridview row. make a for loop and find the radio button in each row and other controls whose value you want to update. check the conditions as per your requirement and update accordingly

how to get the delete row value if I wanna to delete it in gridview (web application)

when i have a gridview, after the user press the delete button, i will like to know that the particular row data in this case, how i get the particular row data?
Sample gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" DataKeyNames="addCartID"
BackColor="White"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None" OnRowDeleted="Delete_Event">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:TemplateField HeaderText="addCartID" InsertVisible="False"
SortExpression="addCartID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("addCartID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("addCartID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="productID" SortExpression="productID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("productID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("productID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="custID" SortExpression="custID">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("custID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("custID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="seatOrderID" SortExpression="seatOrderID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("seatOrderID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("seatOrderID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
Here is the c# code i wanna get the delete value, after user click delete i wish to update something based on the seatOrderID deleted, how do i get it? tq~~
protected void updateBack()
{
Response.Write(I want to get the deleted seatOrderID here!!!!!);
}
Using this code, you can fetch the ID in the RowDeleting event:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow gvr = (GridViewRow)GridView1.Rows[e.RowIndex];
string id = String.Empty;
Label lbl = (gvr.FindControl("Label1") as Label)
if (lbl != null)
{
id = lbl.Text;
}
}
You can fetch any control in the row, using the FindControl() method.

How to bind hovermenuextender control to a row with multiple columns in a dynamic gridview?

I wish to attach a hovermenu pop up to rows of a gridview which is dynamically populated from a datasource. I tried to set TargetcontrolId property of hovermenuextender control to row unique Id on occurence of rowdatabound event. But rather than appearing on the right side of each row, pop up is appearing on the right side of header row. Can somebody help me resolve this problem? I used below code for the same
CodeBehind:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HoverMenuExtender hoverMenu =(HoverMenuExtender)e.Row.FindControl("hme2");
if (hoverMenu != null)
{
hoverMenu.TargetControlID = hoverMenu.Parent.Parent.UniqueID;
}
}
}
}
Aspx page:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" ShowFooter="false" ShowHeader="false"
OnRowEditing="GridView1_RowEditing" OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating"
GridLines="None" OnRowDataBound="GridView1_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText ="Talk Title">
<ItemTemplate>
<asp:Label Font-Bold="true" ID="lbltalktitle" runat="server" Text='<%#Eval("Talk_Title") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Brand">
<ItemTemplate>
<asp:Label ID="lblBrand" runat="server" Text='<%# Eval("Brand") %>' /></td>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Franchise">
<ItemTemplate>
<asp:Label ID="lblFranchise" runat="server" Text='<%# Eval("Franchise") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="programmetype">
<ItemTemplate>
<asp:Label ID="lblprg" runat="server" Text='<%# Eval("programmetype") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="programmetype">
<ItemTemplate>
<asp:Label ID="lblsaledforce" runat="server" Text='<%# Eval("salesforce") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Start_Date">
<ItemTemplate>
<asp:Label ID="lblstartdate" runat="server" Text='<%# Eval("Start_Date") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="End_Date">
<ItemTemplate>
<asp:Label ID="lblenddate" runat="server" Text='<%# Eval("End_Date") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<cc1:HoverMenuExtender ID="hme2" runat="server" TargetControlID="lblenddate"
PopupControlID="PopupMenuX" HoverCssClass="popupHover" PopupPosition="Right"/>
<asp:Panel CssClass="popupMenu" ID="PopupMenuX" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" /><br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete" />
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle ForeColor="Black" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
AjaxControlToolkit.HoverMenuExtender ajxhovermenu = (AjaxControlToolkit.HoverMenuExtender)e.Row.FindControl("ahm_1");
e.Row.ID = e.Row.RowIndex.ToString();
ajxhovermenu.TargetControlID = e.Row.ID;
}
}
Give TargetControlID of the HoverMenuExtender in RowCreated event of GridView and set it as the RowID

Categories