Please forgive me once again for coming back for more.
I have been working on this for most of today and still can't get it to work correctly.
What is most frustrating is that I have used this code in a previous project and everythings fine. This time, I have no idea what is wrong.
I have a Gridview with Button to add new row dynamically and to remove a row dynamically.
By default there is one row. User enters amount into
txttaxpayerret control. The user clicks the button to add a new row and again enters a numeric value. As the value is being entered, total amount is automally added to a label control ID called lblTotal.
So far, so good. The issue is that we are trying to present preview page to the user so user can review and either make a change or submit.
So far, here are two problems.
1, when enter say 20, hit the Add button and then enter a new value say 30, when you click Next to review your entries, we expect to see two rows, one for 20 and the other for 30.
In this case, only the first row is showing 20. The second row is not showing.
Second, nothing is showing in the lblTotalPrev control.
Any ideas what I am doing wrong?
<asp:View ID="vwPersonalInfo" runat="server">
<table border="1" style="width:100%;text-align:center;margin-left:-30px;">
<tr>
<td style="width:100%;vertical-align: text-top;">
<asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="Gridview1" Style="table-layout: fixed;" runat="server" ShowFooter="true"
AutoGenerateColumns="false" onrowdatabound="Gridview1_RowDataBound" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Aircraft Registration #:">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtboatregNum" runat="server" Style="width: 593px;" class="form-control" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TaxPayer Returned Value <br />As of Jan This Year">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txttaxpayerret" runat="server" Style="width: 326px;" class="form-control txttaxpayerret taxInput"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="For Tax Office use Only <br /> (Tax Assessirs Value)">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtfortaxofficeonly" runat="server" Style="width: 305px; background-color: #ECECEC;"
ReadOnly="true" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<HeaderStyle Width="70" />
<ItemStyle Width="70" />
<ItemTemplate>
<asp:Button ID="BtnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" CssClass="grvDelButton" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True">
<ControlStyle CssClass="grvDelButton" />
</asp:CommandField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<table border="1" style="width:100%;text-align:center">
<tr>
<td style="width:24.2%;">TOTAL ></td><td style="width:23%;"><asp:Label ID="lblTotal" runat="server"></asp:Label></td><td style="width:62.8%;"></td>
</tr>
</table>
</asp:view>
<asp:View ID="vwPreview" runat="server">
<table border="1" style="width:100%;text-align:center;">
<tr>
<td style="width:100%;vertical-align: text-top;">
<table cellspacing="0" rules="all" border="1" width="100%" style="border-collapse:collapse;table-layout: fixed;">
<tr>
<th align="left" scope="col">Aircraft Registration #:</th>
<th scope="col">TaxPayer Returned Value <br />As of Jan This Year</th>
<th scope="col">For Tax Office use Only <br /> (Tax Assessirs Value)</th><th scope="col" style="width:70px;"> </th><th scope="col"> </th>
</tr>
<tr>
<td>
<asp:Label id="lblboatregNum" runat="server" class="form-control" style="width:493px;background-color:cornsilk; color: #0093B2;font-weight:bold;" />
</td>
<td align="left">
<asp:Label ID="lbltaxpayerret" runat="server" class="form-control txttaxpayerret" style="width:326px;background-color:cornsilk; color: #0093B2;font-weight:bold;" />
</td>
<td align="left">
<asp:TextBox disabled="disabled" runat="server" id="lblfortaxofficeonly" class="form-control" style="width:305px;color: #0093B2;font-weight:bold;background-color: #ECECEC;" />
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="1" style="width:100%;text-align:center">
<tr>
<td width="24.2%">TOTAL ></td><td style="width:23%"><asp:Label ID="lblTotalPrev" runat="server"></asp:Label></td><td style="width:62.8%"></td>
</tr>
</table>
<br />
</asp:View>
</asp:MultiView>
//Codefile
private void SetRowData()
{
int rowIndex = 0;
if (ViewState["CurrTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
TextBox tbboatregNum = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txtboatregNum");
TextBox tbtaxpayerret = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("txttaxpayerret");
TextBox tbfortaxofficeonly = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("txtfortaxofficeonly");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtCurrentTable.Rows[i - 1]["boatregNum"] = tbboatregNum.Text;
dtCurrentTable.Rows[i - 1]["taxpayerret"] = tbtaxpayerret.Text;
dtCurrentTable.Rows[i - 1]["fortaxofficeonly"] = tbfortaxofficeonly.Text;
rowIndex += 1;
}
ViewState["CurrTable"] = dtCurrentTable;
}
}
else
{
Response.Write("ViewState is null");
}
}
protected override void OnPreRender(EventArgs e)
{
if (myMultiView.ActiveViewIndex == myMultiView.Views.Count - 1)
{
FillSummary();
}
btnBack.Visible = myMultiView.ActiveViewIndex > 0;
btnNext.Visible = myMultiView.ActiveViewIndex < myMultiView.Views.Count - 1;
btnSave.Visible = myMultiView.ActiveViewIndex == myMultiView.Views.Count - 1;
base.OnPreRender(e);
}
private void FillSummary()
{
SetRowData();
lblcitylist.Text = citylist.Text;
lblTotalPrev.Text = lblTotal.Text;
int rowIndex = 0;
if (ViewState["CurrTable"] != null)
{
//Initialize datatables containing income sources of all stripes.
DataTable dtAirInfoTable = (DataTable)ViewState["CurrTable"];
//Lets start looping through the first datatable for source name. We will do this till all income sources are accounted for - till we get to Creditor Income Source. Then we stop.
if (dtAirInfoTable.Rows.Count > 0)
{
////Next collection. Aircraft Information
foreach (DataRow row in dtAirInfoTable.Rows)
{
string txBoatRegNum = row.ItemArray[1] as string;
string txTaxPayerRet = row.ItemArray[2] as string;
string txOfficeO = row.ItemArray[3] as string;
lblboatregNum.Text = txBoatRegNum + "<br />";
lbltaxpayerret.Text = txTaxPayerRet + "<br />";
lblfortaxofficeonly.Text = txOfficeO + "<br />";
rowIndex += 1;
}
}
}
}