I am using a modal popup extender to show a popup window. It it, I have a GridView with editable fields in each row. When I click Submit and handle the click event, the GridView's cells' texts are empty, though other controls, e.g. textboxes contain entered
values. Could you please tell me why the GridView loses its values?
protected void btnSubmitSubmitOffer_Click(object sender, EventArgs e)
{
string commandText;
string errorMessage = "Failed to enter cancellation reason for products with the following EAN: ";
bool bAnyFailures = false;
foreach (GridViewRow row in BookQuestSelectedGridView.Rows) // ALL CELLS ARE EMPTY
{
commandText =
"INSERT INTO Offer (OfferDate, Amount, ExpirationDate, BookQuestID) VALUES('" +
Convert.ToDateTime(row.Cells[1].Text).ToString("yyyy:MM:dd hh:mm:ss") + "'," +
Convert.ToDouble(row.Cells[2].Text) + ",'" +
Convert.ToDateTime(row.Cells[3].Text).ToString("yyyy:MM:dd hh:mm:ss") +
"', (SELECT ID FROM BookQuest WHERE EAN = '" + row.Cells[0].Text + "'))";
result = DBOperations.Execute(true, CommandType.Text, null, commandText);
if (result != null && !Int32.TryParse(result.ToString(), out recordsUpdated)) // exception was thrown: if the returned value is not the number of updated records, it is an error message
{
errorMessage += "<br>" + row.Cells[0].Text + " : " + result.ToString();
bAnyFailures = true;
}
}
if (bAnyFailures)
{
SetWarningLabel(errorMessage);
}
Filter();
}
dpreznik
Member
122 Points
351 Posts
GridView in ModalPopup window is empty
Mar 01, 2010 02:16 PM|LINK
Dear friends,
I am using a modal popup extender to show a popup window. It it, I have a GridView with editable fields in each row. When I click Submit and handle the click event, the GridView's cells' texts are empty, though other controls, e.g. textboxes contain entered values. Could you please tell me why the GridView loses its values?
Here is my code:
<asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager> <asp:Panel ID="pnlSubmitOffer" runat="server" CssClass="modalPopup" Style="display:none" Width="700px" > <asp:GridView ID="BookQuestSelectedGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False" Width="100%" Height="306px" DataKeyNames="EAN" > <AlternatingRowStyle CssClass="alternatingrowstyle" /> <Columns> <asp:BoundField DataField="EAN" HeaderText="EAN" SortExpression="EAN" /> <asp:TemplateField HeaderText="Offer Date" SortExpression="OfferDate"> <ItemTemplate> <asp:ImageButton runat="Server" ID="imgBtnOfferDate" ImageUrl="~/Images/Calendar_scheduleHS.png" AlternateText="Click here to display calendar" /> <asp:TextBox ID="OfferDate" runat="server" Text='<%# Bind("OfferDate","{0:M/d/yyyy}") %>'></asp:TextBox> <ajaxToolkit:CalendarExtender ID="OfferDateCE" runat="server" TargetControlID="OfferDate" PopupButtonID="imgBtnOfferDate"/> <asp:CompareValidator ID="OfferDateCompareValidator" runat="server" ControlToValidate="OfferDate" Display="Dynamic" ErrorMessage="Invalid OfferDate!" Text="*" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator> <ajaxToolkit:ValidatorCalloutExtender ID="OfferDateCompareValidator_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="OfferDateCompareValidator"></ajaxToolkit:ValidatorCalloutExtender> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Amount" SortExpression="Amount"> <ItemTemplate> <asp:TextBox ID="Amount" runat="server" Text='<%#Bind("Amount") %>'></asp:TextBox> <asp:CompareValidator ID="AmountCompareValidator" runat="server" ControlToValidate="Amount" Display="Dynamic" ErrorMessage="Amount has invalid currency value!" Text="*" Operator="DataTypeCheck" Type="Currency"></asp:CompareValidator> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Expiration Date" SortExpression="ExpirationDate"> <ItemTemplate> <asp:ImageButton runat="Server" ID="imgBtnExpirationDate" ImageUrl="~/Images/Calendar_scheduleHS.png" AlternateText="Click here to display calendar" /> <asp:TextBox ID="ExpirationDate" runat="server" Text='<%# Bind("ExpirationDate","{0:M/d/yyyy}") %>'></asp:TextBox> <ajaxToolkit:CalendarExtender ID="ExpirationDateCE" runat="server" TargetControlID="ExpirationDate" PopupButtonID="imgBtnExpirationDate"/> <asp:CompareValidator ID="ExpirationDateCompareValidator" runat="server" ControlToValidate="ExpirationDate" Display="Dynamic" ErrorMessage="Invalid ExpirationDate!" Text="*" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator> <ajaxToolkit:ValidatorCalloutExtender ID="ExpirationDateCompareValidator_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="ExpirationDateCompareValidator"></ajaxToolkit:ValidatorCalloutExtender> </ItemTemplate> </asp:TemplateField> </Columns> <HeaderStyle CssClass="headerstyle" /> </asp:GridView> <div align="center"> <asp:Button ID="btnSubmitSubmitOffer" runat="server" Text="Submit" OnClick="btnSubmitSubmitOffer_Click" /> <asp:Button ID="btnCancelSubmitOffer" runat="server" Text="Cancel" /> </div> </asp:Panel>protected void btnSubmitSubmitOffer_Click(object sender, EventArgs e) { string commandText; string errorMessage = "Failed to enter cancellation reason for products with the following EAN: "; bool bAnyFailures = false; foreach (GridViewRow row in BookQuestSelectedGridView.Rows) // ALL CELLS ARE EMPTY { commandText = "INSERT INTO Offer (OfferDate, Amount, ExpirationDate, BookQuestID) VALUES('" + Convert.ToDateTime(row.Cells[1].Text).ToString("yyyy:MM:dd hh:mm:ss") + "'," + Convert.ToDouble(row.Cells[2].Text) + ",'" + Convert.ToDateTime(row.Cells[3].Text).ToString("yyyy:MM:dd hh:mm:ss") + "', (SELECT ID FROM BookQuest WHERE EAN = '" + row.Cells[0].Text + "'))"; result = DBOperations.Execute(true, CommandType.Text, null, commandText); if (result != null && !Int32.TryParse(result.ToString(), out recordsUpdated)) // exception was thrown: if the returned value is not the number of updated records, it is an error message { errorMessage += "<br>" + row.Cells[0].Text + " : " + result.ToString(); bAnyFailures = true; } } if (bAnyFailures) { SetWarningLabel(errorMessage); } Filter(); }Thanks,
Dmitriy
<input id="gwProxy" type="hidden"><input onclick="jsCall();" id="jsProxy" type="hidden">
<div id="refHTML"></div>dpreznik
Member
122 Points
351 Posts
Re: GridView in ModalPopup window is empty
Mar 01, 2010 04:36 PM|LINK
Never mind, I got it. I had to use FindControl(), as I was dealing with templete fields.