I am having an issue. I have a page that has a Gridview with edit/update/cancel edit on it.
The page works/renders until I add the OnRowUpdating="UpdateRow" to the Gridview. Then the page does not render at all.
In Debugging it does not even get to the page load events. When I take this property out of the Gridview (without touching any code behind code) the page renders. I have been googling and can not find anything similar. I can find if it does not fire/does not work but nothing about page not rendering.
My code is below:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="false"
Width="100%"
OnRowEditing="EditRow"
OnRowUpdating="UpdateRow"
OnRowCancelingEdit="CancelEditRow"
DataKeyNames="OnCallID"
AllowPaging="true"
PageSize="50"
OnPageIndexChanging="ChangePage"
OnRowDataBound="gvVehicle_OnRowDataBound"
>
<Columns>
<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="25px">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update" />
<asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="OnCallID" DataField="OnCallID" ReadOnly="true" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="25px" Visible="false" />
<asp:TemplateField HeaderText="OnCallID" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" Visible="false" >
<ItemTemplate><%# Eval("OnCallID")%></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="HDNOnCallID" runat="server" Visible="true" Text='<%# Eval("OnCallID")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Team Member Name" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("TeamMemberName")%></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="LBLUserIDLST" runat="server" Visible="true" Text='<%# Eval("TeamMemberName")%>' />
<!--<asp:ListBox ID="UserIDLST" runat="server" SelectionMode="Single" Visible="true" Width="100" Rows="1"></asp:ListBox> -->
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call Start Date" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallStartDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="StartDateEditUpdate" runat="server" MaxLength="10" name="StartDateEditUpdate" Width="70" Text='<%# Eval("OnCallStartDate")%>'></asp:TextBox>
<asp:Image id="StartDateEditUpdateCalImg" runat="server" ImageUrl="../Images/CalendarImg.png" ImageAlign="Bottom" />
<ajaxToolkit:CalendarExtender ID="extendStartDateEditUpdate" runat="server" CssClass="datePicker" PopupPosition="TopLeft"
TargetControlID="StartDateEditUpdate" Format="MM/dd/yyyy" PopupButtonID="StartDateEditUpdateCalImg">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="validateStartDateEditUpdate"
ControlToValidate="StartDateEditUpdate"
Text="You must Type Something in for Start Date!"
runat="server"
Enabled="true"
CssClass="validatorErrorDisplay"
/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call Start Time" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallStartTime")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="StartTimeEditUpdate" runat="server" MaxLength="10" Width="100" Text='<%# Eval("OnCallStartTime")%>'></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditorStartTimeEditUpdate" runat="server"
TargetControlID="StartTimeEditUpdate"
Mask="99:99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Time"
InputDirection="LeftToRight"
ErrorTooltipEnabled="True"
AcceptAMPM="true"
AutoComplete="true"
/>
<ajaxToolkit:MaskedEditValidator ID="MaskedEditorValidatorStartTimeEditUpdate" runat="server"
ControlExtender="MaskedEditorStartTimeEditUpdate"
ControlToValidate="StartTimeEditUpdate"
IsValidEmpty="true"
AcceptAMPM = "true"
InvalidValueMessage="This is not a valid time2"
InvalidValueBlurredMessage="This is not a valid time"
Enabled="true"
TooltipMessage="Must be in Time format HH:MM AM/PM"
ValidationExpression="(0[1-9]|1[0-2]):([0-5][0-9]) (AM|PM|am|pm)"
/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call End Date" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallEndDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EndDateEditUpdate" runat="server" MaxLength="10" name="EndDateEditUpdate" Width="70" Text='<%# Eval("OnCallEndDate")%>'></asp:TextBox>
<asp:Image id="EndDateEditUpdateCalImg" runat="server" ImageUrl="../Images/CalendarImg.png" ImageAlign="Bottom" />
<ajaxToolkit:CalendarExtender ID="extendEditUpdate" runat="server" CssClass="datePicker" PopupPosition="TopLeft"
TargetControlID="EndDateEditUpdate" Format="MM/dd/yyyy" PopupButtonID="EndDateEditUpdateCalImg">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="validateEndDateEditUpdate"
ControlToValidate="EndDateEditUpdate"
Text="You must Type Something in for End Date!"
runat="server"
Enabled="true"
CssClass="validatorErrorDisplay"
/>
<asp:CompareValidator ID="CompareStartDateEndDateEditUpdateValidator" Operator="GreaterThanEqual" Type="Date"
ControlToValidate="EndDateEditUpdate" ControlToCompare="StartDateEditUpdate"
ErrorMessage="End Date must be greater then Start Date!" runat="server" BackColor="Red" ForeColor="White" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call End Time" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallEndTime")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EndTimeEditUpdate" runat="server" MaxLength="10" Width="100" Text='<%# Eval("OnCallEndTime")%>'></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditorEndTimeEditUpdate" runat="server"
TargetControlID="EndTimeEditUpdate"
Mask="99:99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Time"
InputDirection="LeftToRight"
ErrorTooltipEnabled="True"
AcceptAMPM="true"
AutoComplete="true"
/>
<ajaxToolkit:MaskedEditValidator ID="MaskedEditorValidatorEndTimeEditUpdate" runat="server"
ControlExtender="MaskedEditorEndTimeEditUpdate"
ControlToValidate="EndTimeEditUpdate"
IsValidEmpty="true"
AcceptAMPM = "true"
InvalidValueMessage="This is not a valid time2"
InvalidValueBlurredMessage="This is not a valid time"
Enabled="true"
TooltipMessage="Must be in Time format HH:MM AM/PM"
ValidationExpression="(0[1-9]|1[0-2]):([0-5][0-9]) (AM|PM|am|pm)"
/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#efefef" />
<FooterStyle BackColor="#F37721" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#F37721" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
protected void EditRow(object sender, GridViewEditEventArgs e)
{
// this enables/disables the add new row validation
EnableDisableValidationsAndButtons(false);
GridView1.EditIndex = e.NewEditIndex;
this.PopulateData();
}
protected void CancelEditRow(object sender, GridViewCancelEditEventArgs e)
{
// this enables/disables the add new row validation
EnableDisableValidationsAndButtons(true);
GridView1.EditIndex = -1;
this.PopulateData();
}
protected void UpdateRow(object sender, GridViewUpdatedEventArgs e)
{
//GridViewRow row = (GridViewRow)GridView1.Rows[e.NewEditIndex];
GridViewRow row = (GridViewRow)GridView1.Rows[GridView1.EditIndex];
Label txtOnCallID = (Label)row.FindControl("HDNOnCallID");
String OnCallID = txtOnCallID.Text.ToString();
TextBox txtBoxStartDate = (TextBox)row.FindControl("StartDate");
String StartDate = txtBoxStartDate.Text.ToString();
TextBox txtBoxStartTime = (TextBox)row.FindControl("StartTime");
String StartTime = txtBoxStartTime.Text.ToString();
TextBox txtBoxEndDate = (TextBox)row.FindControl("EndDate");
String EndDate = txtBoxStartDate.Text.ToString();
TextBox txtBoxEndTime = (TextBox)row.FindControl("EndTime");
String EndTime = txtBoxEndTime.Text.ToString();
// do update stuff here
SQL CODE HERE
// run update
//new DatabaseConnection().RSExecute(sCommand);
lblMessage.Text = "Record successfully Updated!";
GridView1.EditIndex = -1;
//this.PopulateData();
// doing a redirect here for the full URL because if you refresh page it adds the record duplicate times
// also some of the form fields are still filled out, this removes them as well
Response.Redirect(Request.Url.AbsoluteUri);
}
Change the signature of the function as below and check. You are binding function with GridViewUpdatedEventArgs instead of GridViewUpdateEventArgs
protected void UpdateRow(object sender, GridViewUpdateEventArgs e)
{
}
Related
I want to update the text of the btn_Update which is inside the EditTemplate of gridview. For that I wrote the code shown here. But the text is still shown as Reject, even if I am trying to update the text to Approve.
Here's my markup and code:
<asp:GridView ID="rptHotoIPDataInfo" runat="server" AutoGenerateColumns="False" CssClass="table table-bordered nowrap tblrptHotoIPDataInfo"
AllowPaging="True" PageSize="20" OnPageIndexChanging="rptHotoIPDataInfo_PageIndexChanging"
DataKeyNames="SAP_ID" OnRowEditing="rptHotoIPDataInfo_RowEditing" OnRowUpdating="rptHotoIPDataInfo_RowUpdating"
OnRowCancelingEdit="rptHotoIPDataInfo_RowCancelingEdit" OnRowDataBound="rptHotoIPDataInfo_RowDataBound"
OnRowCommand="rptHotoIPDataInfo_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Approved / Reject" ItemStyle-Width="80px"> <%--"Accepted/Rejected (By default checked means approved)"--%>
<ItemTemplate >
<asp:CheckBox ID="chkRow" runat="server" Checked="true" Width="5px" OnCheckedChanged="chkRow_CheckedChanged"
AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-Width="120px">
<ItemTemplate>
<asp:Button ID="btn_Edit" runat="server" Text="Reject" CommandName="Edit" Enabled="false" CssClass="btn btn-blue" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btn_Update" runat="server" Text="Reject" CommandName="Update" CssClass="btn btn-blue" />
<asp:Button ID="btn_Cancel" runat="server" Text="Cancel" CommandName="Cancel" CssClass="btn btn-blue" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rejected Remarks" ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="lblRemarks" runat="server" Text='<%#Eval("REJECT_REMARKS") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtRemarks" runat="server" Text='<%#Eval("REJECT_REMARKS") %>' Width="150px" CssClass="form-control"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="lbl_ID" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SAP_ID" HeaderText="SAP ID">
<ItemStyle CssClass="labelbold" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="CR_NO" HeaderText="Description" Visible="False">
<ItemStyle CssClass="labelbold" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="R4GSTATE_CODE" HeaderText="State Code">
<ItemStyle CssClass="labelbold" Width="30px" />
</asp:BoundField>
<asp:BoundField DataField="HOTO_STATUS" HeaderText="Hoto Status">
<ItemStyle CssClass="labelbold" Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="CR_Justifications" HeaderText="CR Justifications">
<ItemStyle CssClass="labelbold" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="APPROVE_REJECT" HeaderText="Status">
<ItemStyle CssClass="labelbold" Width="10px" />
</asp:BoundField>
<asp:BoundField DataField="REJECTED_BY" HeaderText="Last Updated by">
<ItemStyle CssClass="labelbold" Width="10px" />
</asp:BoundField>
</Columns>
</asp:GridView>
And the code behind is:
protected void rptHotoIPDataInfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = rptHotoIPDataInfo.Rows[rowIndex];
string name = row.Cells[9].Text;
var clickedButton = e.CommandSource as Button;
var clickedRow = clickedButton.NamingContainer as GridViewRow;
var clickedUserName = clickedRow.Cells[9].Text;
if (clickedUserName == "Approved")
{
clickedButton.Text = "Reject";
}
else if (clickedUserName == "REJECTED")
{
clickedButton.Text = "Approve"; // this statement is not updating the text
}
}
}
Aspx Code:
<asp:GridView ID="PaperReviewing" runat="server" CellPadding="4" EmptyDataText="There is no Submission"DataKeyNames="PaperId" RowStyle-Wrap="true" OnRowDataBound="PaperReviewing_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Action" ControlStyle-Width="200px" >
<ItemTemplate>
<br />
<asp:HyperLink ID="HyperLink3" Target="_blank" ForeColor="Black" onclick="javascript:window.open(this.href,'ManuScript Details','resizable=no,scroll bars=yes,status=no,toolbar=yes,height=500,width=700,left=50,top=40');return true;"
NavigateUrl='<%# String.Format("~/EditorsInChief/DownloadSubFileList.aspx?ID={0}", Eval("PaperId")) %>' runat="server">File Inventory</asp:HyperLink>
<br /><asp:HyperLink ID="HyperLink4" Target="_blank" ForeColor="Black" onclick="javascript:window.open(this.href,'ManuScript Details','resizable=no,scroll bars=yes,status=no,toolbar=yes,height=500,width=700,left=50,top=40');return true;"
NavigateUrl='<%# String.Format("~/EditorsInChief/SelectReviewer.aspx?ID={0}", Eval("PaperId")) %>' runat="server">Select Another Reviewer</asp:HyperLink>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PaperId" HeaderText="PaperId" InsertVisible="False"
ReadOnly="True" SortExpression="PaperId" Visible="False" />
<asp:BoundField DataField="ManuScriptId" HeaderText="ManuScript Number"
SortExpression="ManuScriptId" />
<asp:BoundField DataField="Type" HeaderText="Article Type" SortExpression="Type" />
<asp:TemplateField HeaderText="Article Title" HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Left" SortExpression="PaperTitle" ControlStyle-Width="200px">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("PaperTitle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ReviewerName" HeaderText="Reviewer Name" SortExpression="ReviewerName" />
<asp:BoundField DataField="Status" HeaderText="Current Status"
SortExpression="Status" />
<asp:BoundField DataField="CreatedDate" HeaderText="Intital Date Submission" SortExpression="CreatedDate" />
<asp:BoundField DataField="DateReviewInvited" HeaderText="Date Review Invited"
SortExpression="DateReviewInvited" />
<asp:BoundField DataField="DateReviewDue" HeaderText="Date Review Due"
SortExpression="DateReviewDue" />
<asp:TemplateField HeaderText="EIC Decision">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True" Text="Choose Option"></asp:ListItem>
<asp:ListItem Text="Accept" Value="Accept"></asp:ListItem>
<asp:ListItem Text="Reject" Value="Reject"></asp:ListItem>
<asp:ListItem Text="Minor Revision" Value="MinorRevision"></asp:ListItem>
<asp:ListItem Text="Major Revision" Value="MajorRevision"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" BorderStyle="Double" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
C# Code :
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DropDownList1 = (DropDownList)sender;
GridViewRow grdrDropDownRow = ((GridViewRow)DropDownList1.Parent.Parent);
}
protected void PaperReviewing_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;
if (ddl != null)
{
ddl.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
}
}
}
the drop down selectedindexchanged event does not fire. I am trying to do as my drop down value changes at run time , in my database value get updates.
remove the event handler adding code from PaperReviewing_RowDataBound since you are already attached it from the markup
in your page load
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
DataBindGrid();
}
}
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.
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
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).