|
I think you need to try a little bit harder yourself first, rather than asking for such general help. If you search online for "asp.net repeater examples" you will find plenty of help to get your started.
|
|
|
|
|
I searched Alot but no solution found that's why i am asking for help. Dear
|
|
|
|
|
Well, the best thing to do when stuck on any problem is to first try to solve a simpler one. SO I suggest you follow some of the simple examples you can find on the Internet to get a better understanding of how to use the repeater control. You should then be able to make a start on what you want to do, and can come back and ask with some specific problems if you still have any.
|
|
|
|
|
ok i will try it, but it would be better if i have found a solution here on this forum
THanks Dear
|
|
|
|
|
No - it might be easier to be given an answer, but better is to learn for yourself. Also, while it might be easier for you, it would be harder for others who volunteer their time to help on these forums.
|
|
|
|
|
yeah you ar right but this time it is harder for me
|
|
|
|
|
Having done as was suggested by G_Griffin ie: search ASP.Net Repeater control examples, and selecting videos as my filter I found an excellent lesson from an old friend "Kudvenkat" on Youtube here (https://www.youtube.com/watch?v=v3w0XWWyVO4). It may be after you watch the following video, you may decide to instead use a gridview control, but either way this is an excellent lesson for introducing the repeater control.
I learn best by watching video lessons and writing the code as a follow along method and I have learned most of my coding languages from kudvenkat and a few others.
|
|
|
|
|
I am struggling with trying to figure out how I can output a trace message in ASP.NET using the Trace.Write() method inside of a for loop in order for a user to see the future value after 1 month, 10 months, and 50 months? The format should be like this:
Month{i}: & Value{futureValue}. So, for example, the format should look like this after the first month: "Month:" {i} "Value:"{futureValue}. i know that's not right but that's why I need help understanding how I can input the variables correctly into this method. I have researched my problem, but it's not specific to my individual problem. Here is the site I have researched before coming here: (http://www.c-sharpcorner.com/UploadFile/225740/how-to-write-custom-tracing-message-in-Asp-Net/)
<pre lang="c#"><pre>namespace XEx05FutureValue
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
for (int i = 50; i <= 500; i += 50)
ddlMonthlyInvestment.Items.Add(i.ToString());
}
protected void btnCalculate_Click(object sender, EventArgs e)
{
if (IsValid)
{
int monthlyInvestment = Convert.ToInt32(ddlMonthlyInvestment.SelectedValue);
decimal yearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text);
int years = Convert.ToInt32(txtYears.Text);
decimal futureValue = this.CalculateFutureValue(monthlyInvestment,
yearlyInterestRate, years);
lblFutureValue.Text = futureValue.ToString("c");
}
}
protected decimal CalculateFutureValue(int monthlyInvestment,
decimal yearlyInterestRate, int years)
{
int months = years * 12;
decimal monthlyInterestRate = yearlyInterestRate / 12 / 100;
decimal futureValue = 0;
for (int i = 0; i < months; i++)
{
futureValue = (futureValue + monthlyInvestment)
* (1 + monthlyInterestRate);
if (Trace.IsEnabled)
{
Trace.Write({i} {futureValue});
}
}
return futureValue;
}
protected void btnClear_Click(object sender, EventArgs e)
{
ddlMonthlyInvestment.SelectedIndex = 0;
txtInterestRate.Text = "";
txtYears.Text = "";
lblFutureValue.Text = "";
}
}
}
|
|
|
|
|
Dorakta wrote: ... in order for a user to see ...
Trace output is intended to help the developer when building the site. It should never be shown to the end user.
If you want to show something to the user, then you need to add it to the page somewhere.
Markup:
<dl>
<asp:placeholder id="futureValueList" runat="server" />
</dl> Code:
for (int i = 0; i < months; i++)
{
futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate);
Trace.Write(string.Format("{0}: {1:C}", i, futureValue));
var dt = new HtmlGenericControl("dt");
dt.InnerText = string.Format("{0} months", i);
futureValueList.Controls.Add(dt);
var dd = new HtmlGenericControl("dd");
dd.InnerText = futureValue.ToString("C");
futureValueList.Controls.Add(dd);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I wrote a UPS Rate Quote Service in c# using the supplied WSDL file.
So now I'm testing it, at first the error in transmitting the SOAP file was "An exception has been raised as a result of client data." and the catch would catch it using Exception. Same thing with FaultException.
I read the stack trace, it refers to the Soap call to ProcessRate(Security, Request) in reference.cs and went to line 6492 and 6499.
I wrote another class as the bare minimum and transmitted again and got the same result.
I really don't know how to proceed here.
Soap Call
try
{
using (var client = new ups_rateService.RatePortTypeClient(new BasicHttpBinding(BasicHttpSecurityMode.Transport), new EndpointAddress(endpointUrl)))
{
pResult = client.ProcessRate(Security, pRequest);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
Resources.cs
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
Indigo.Services.ups_rateService.RateResponse1 Indigo.Services.ups_rateService.RatePortType.ProcessRate(Indigo.Services.ups_rateService.RateRequest1 request) {
return base.Channel.ProcessRate(request);
}
public Indigo.Services.ups_rateService.RateResponse ProcessRate(Indigo.Services.ups_rateService.UPSSecurity UPSSecurity, Indigo.Services.ups_rateService.RateRequest RateRequest) {
Indigo.Services.ups_rateService.RateRequest1 inValue = new Indigo.Services.ups_rateService.RateRequest1();
inValue.UPSSecurity = UPSSecurity;
inValue.RateRequest = RateRequest;
Indigo.Services.ups_rateService.RateResponse1 retVal = ((Indigo.Services.ups_rateService.RatePortType)(this)).ProcessRate(inValue);
return retVal.RateResponse;
}
Stack Trace
System.ServiceModel.FaultException`1 occurred
HResult=0x80131501
Message=An exception has been raised as a result of client data.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Indigo.Services.ups_rateService.RatePortType.ProcessRate(RateRequest1 request)
at Indigo.Services.ups_rateService.RatePortTypeClient.Indigo.Services.ups_rateService.RatePortType.ProcessRate(RateRequest1 request) in J:\Indigo.Services\Service References\ups_rateService\Reference.cs:line 6492
at Indigo.Services.ups_rateService.RatePortTypeClient.ProcessRate(UPSSecurity UPSSecurity, RateRequest RateRequest) in J:\Indigo.Services\Service References\ups_rateService\Reference.cs:line 6499
at Indigo.Services.UPS_Soap_Rate.transmit_request(model_shipRates_rate_request p, RateRequest pRequest) in J:\Indigo.Services\Business Logic\Ship Processors\UPS\UPS_Soap_Rate.cs:line 203
If it ain't broke don't fix it
|
|
|
|
|
Well the documentation is dated Jun 2017 and the WSDL file is dated Dec 2007. So this WSDL was current as of VS2010.
Guess I'll toss it in the scrape pile and go back to XML or try the JSON version.
If it ain't broke don't fix it
|
|
|
|
|
It works!
The message "An exception has been raised as a result of client data" basically means that something as dumb as having the country code in the postal code field will crash the UPS Web Service and return this error message.
So I spent the day firing up the sample code from UPS written in 2007. Took awhile to upgrade and make code changes but got it to work.
To get the WebReference to work you have to go to proprties and paste in the current location of the WSDL file. Then on the ProcessRate you add
RateService rate = new RateService() { UPSSecurityValue = Security, Url = endpointUrl };
pResult = rate.ProcessRate(pRequest);
Then placed the working code in my new project, and made a Web Reference for the WSDL and debuged the code till it worked. Use the RateService to call the UPS Service and continued to debug until it returned a list of rates.
Then I referenced back to the Service Reference and placed the soap client and binding back and test fired it to produce a list a rates.
using (var client = new ups_rateService.RatePortTypeClient(new BasicHttpBinding(BasicHttpSecurityMode.Transport), new EndpointAddress(endpointUrl)))
{
pResult = client.ProcessRate(Security, pRequest);
}
So yes this old WSDL works in VS2017 just fine as a Service Reference, but it's the UPS server side and SOAP Exception that will mislead you in hunting down your errors.
If it ain't broke don't fix it
|
|
|
|
|
Hi Richard, sorry to call you out but can you please help me on this issue?
I have been stomped by this now for almost 2 days.
I dynamically creating rows for both Repeater1 and Repeater2.
There is a form field called MarineRegNo on Repeater1.
Once a user enters value for this field and clicks the Next button, that value is transferred a form field called aRegNo in Repeater2.
The issue we are having is that if it is just one row, this value is not getting populated in Repeater2.
If there are two rows for instance, the first row in Repeater2 is not getting populated with value for aRegNo. However, the second row is getting populated with values for aRegNo for Repeater2.
I believe the issue lines with SetInitialRow and SetInitialRow2 functions as I think the values are getting overwritten.
Do you have any ideas how I can resolve this?
There is a ton more codes but I think the two functions below are the relevant codes that are causing the problems.
Thanks as usual for your assistance.
<pre> private void SetInitialRow()
{
myMultiView.ActiveViewIndex = 0;
DataTable dt;
if (ViewState["CurrTable"] == null)
{
dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("ID", typeof(string)));
dt.Columns.Add(new DataColumn("MarineRegNo", typeof(string)));
dt.Columns.Add(new DataColumn("TaxPyrRetdVal", typeof(string)));
dt.Columns.Add(new DataColumn("VesselRegNo", typeof(string)));
dt.Columns.Add(new DataColumn("VesselTaxPyrRetdVal", typeof(string)));
dr = dt.NewRow();
dr["ID"] = 1;
dr["MarineRegNo"] = string.Empty;
dr["TaxPyrRetdVal"] = string.Empty;
dr["VesselRegNo"] = string.Empty;
dr["VesselTaxPyrRetdVal"] = string.Empty;
dt.Rows.Add(dr);
}
else
{
dt = (DataTable)ViewState["CurrTable"];
}
ViewState["CurrTable"] = dt;
if (dt.Rows.Count > 0)
{
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
private void SetInitialRow2(string registerNumber, string bregisterNumber)
{
DataTable dts;
if (ViewState["CurrentTable"] == null)
{
dts = new DataTable();
DataRow dr = null;
//Create DataTable columns
dts.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dts.Columns.Add(new DataColumn("boatcnty", typeof(string)));
dts.Columns.Add(new DataColumn("aRegNo", typeof(string)));
dts.Columns.Add(new DataColumn("aMake", typeof(string)));
dts.Columns.Add(new DataColumn("mMake", typeof(string)));
dts.Columns.Add(new DataColumn("ModelNoA", typeof(string)));
dts.Columns.Add(new DataColumn("ModelNoM", typeof(string)));
dts.Columns.Add(new DataColumn("boatYrBuilt", typeof(string)));
dts.Columns.Add(new DataColumn("motorYrBuilt", typeof(string)));
dts.Columns.Add(new DataColumn("blength", typeof(string)));
dts.Columns.Add(new DataColumn("hullmaterial", typeof(string)));
dts.Columns.Add(new DataColumn("mhorsepower", typeof(string)));
dts.Columns.Add(new DataColumn("rdlmhorsepType", typeof(string)));
dts.Columns.Add(new DataColumn("datePurchased", typeof(string)));
dts.Columns.Add(new DataColumn("mdatePurchased", typeof(string)));
dts.Columns.Add(new DataColumn("PurchaseType", typeof(string)));
dts.Columns.Add(new DataColumn("rblmPurchasedType", typeof(string)));
dts.Columns.Add(new DataColumn("PrevOnwerName", typeof(string)));
dts.Columns.Add(new DataColumn("prevAddr", typeof(string)));
dts.Columns.Add(new DataColumn("prevCity", typeof(string)));
dts.Columns.Add(new DataColumn("PrevState", typeof(string)));
dts.Columns.Add(new DataColumn("prevzip", typeof(string)));
dts.Columns.Add(new DataColumn("mPrevOnwerName", typeof(string)));
dts.Columns.Add(new DataColumn("mprevAddr", typeof(string)));
dts.Columns.Add(new DataColumn("mprevCity", typeof(string)));
dts.Columns.Add(new DataColumn("mPrevState", typeof(string)));
dts.Columns.Add(new DataColumn("mprevzip", typeof(string)));
dts.Columns.Add(new DataColumn("buyername", typeof(string)));
dts.Columns.Add(new DataColumn("buyeraddress", typeof(string)));
dts.Columns.Add(new DataColumn("buyercity", typeof(string)));
dts.Columns.Add(new DataColumn("buyerstate", typeof(string)));
dts.Columns.Add(new DataColumn("buyerzip", typeof(string)));
dts.Columns.Add(new DataColumn("datesold", typeof(string)));
dts.Columns.Add(new DataColumn("salePrice", typeof(string)));
dts.Columns.Add(new DataColumn("Description", typeof(string)));
dts.Columns.Add(new DataColumn("mbuyername", typeof(string)));
dts.Columns.Add(new DataColumn("mbuyeraddress", typeof(string)));
dts.Columns.Add(new DataColumn("mbuyercity", typeof(string)));
dts.Columns.Add(new DataColumn("mbuyerstate", typeof(string)));
dts.Columns.Add(new DataColumn("mbuyerzip", typeof(string)));
dts.Columns.Add(new DataColumn("mdatesold", typeof(string)));
dts.Columns.Add(new DataColumn("msalePrice", typeof(string)));
dts.Columns.Add(new DataColumn("mDescription", typeof(string)));
dts.Columns.Add(new DataColumn("boatCost", typeof(string)));
dts.Columns.Add(new DataColumn("motorCost", typeof(string)));
dts.Columns.Add(new DataColumn("rblIssues", typeof(string)));
dts.Columns.Add(new DataColumn("functionalIsses", typeof(string)));
dts.Columns.Add(new DataColumn("mrblIssues", typeof(string)));
dts.Columns.Add(new DataColumn("mfunctionalIsses", typeof(string)));
dts.Columns.Add(new DataColumn("vesseltypeUse", typeof(string)));
dts.Columns.Add(new DataColumn("vesselname", typeof(string)));
dts.Columns.Add(new DataColumn("vessellength", typeof(string)));
dts.Columns.Add(new DataColumn("vesselYrBult", typeof(string)));
dts.Columns.Add(new DataColumn("VesselHullMateria", typeof(string)));
dts.Columns.Add(new DataColumn("vesselhorsepEngine", typeof(string)));
dts.Columns.Add(new DataColumn("coastGuardNumber", typeof(string)));
dts.Columns.Add(new DataColumn("VesselYrPurchased", typeof(string)));
dts.Columns.Add(new DataColumn("PurchasedNew", typeof(string)));
dts.Columns.Add(new DataColumn("VesselPurchaseAmt", typeof(string)));
dts.Columns.Add(new DataColumn("homePort", typeof(string)));
dts.Columns.Add(new DataColumn("whereDocked", typeof(string)));
dts.Columns.Add(new DataColumn("bmequipAccessoryList", typeof(string)));
//Create Row for each columns
dr = dts.NewRow();
dr["RowNumber"] = 1;
dr["boatcnty"] = string.Empty;
dr["aRegNo"] = registerNumber;
dr["aMake"] = string.Empty;
dr["mMake"] = string.Empty;
dr["ModelNoA"] = string.Empty;
dr["ModelNoM"] = string.Empty;
dr["boatYrBuilt"] = string.Empty;
dr["motorYrBuilt"] = string.Empty;
dr["blength"] = string.Empty;
dr["hullmaterial"] = string.Empty;
dr["mhorsepower"] = string.Empty;
dr["rdlmhorsepType"] = string.Empty;
dr["datePurchased"] = string.Empty;
dr["mdatePurchased"] = string.Empty;
dr["PurchaseType"] = string.Empty;
dr["rblmPurchasedType"] = string.Empty;
dr["PrevOnwerName"] = string.Empty;
dr["prevAddr"] = string.Empty;
dr["prevCity"] = string.Empty;
dr["PrevState"] = string.Empty;
dr["prevzip"] = string.Empty;
dr["mPrevOnwerName"] = string.Empty;
dr["mprevAddr"] = string.Empty;
dr["mprevCity"] = string.Empty;
dr["mPrevState"] = string.Empty;
dr["mprevzip"] = string.Empty;
dr["buyername"] = string.Empty;
dr["buyeraddress"] = string.Empty;
dr["buyercity"] = string.Empty;
dr["buyerstate"] = string.Empty;
dr["buyerzip"] = string.Empty;
dr["datesold"] = string.Empty;
dr["salePrice"] = string.Empty;
dr["Description"] = string.Empty;
dr["mbuyername"] = string.Empty;
dr["mbuyeraddress"] = string.Empty;
dr["mbuyercity"] = string.Empty;
dr["mbuyerstate"] = string.Empty;
dr["mbuyerzip"] = string.Empty;
dr["mdatesold"] = string.Empty;
dr["msalePrice"] = string.Empty;
dr["mDescription"] = string.Empty;
dr["boatCost"] = string.Empty;
dr["motorCost"] = string.Empty;
dr["rblIssues"] = string.Empty;
dr["functionalIsses"] = string.Empty;
dr["mrblIssues"] = string.Empty;
dr["mfunctionalIsses"] = string.Empty;
dr["vesseltypeUse"] = string.Empty;
dr["vesselname"] = string.Empty;
dr["vessellength"] = string.Empty;
dr["vesselYrBult"] = string.Empty;
dr["VesselHullMateria"] = string.Empty;
dr["vesselhorsepEngine"] = string.Empty;
dr["coastGuardNumber"] = bregisterNumber;
dr["VesselYrPurchased"] = string.Empty;
dr["PurchasedNew"] = string.Empty;
dr["VesselPurchaseAmt"] = string.Empty;
dr["homePort"] = string.Empty;
dr["whereDocked"] = string.Empty;
dr["bmequipAccessoryList"] = string.Empty;
dts.Rows.Add(dr);
}
else
{
dts = (DataTable)ViewState["CurrentTable"];
}
//Store the DataTable in ViewState for future reference
ViewState["CurrentTable"] = dts;
if (dts.Rows.Count > 0)
{
Repeater2.DataSource = dts;
Repeater2.DataBind();
}
}
|
|
|
|
|
How are the functions called? And how is the value of the field from the first repeater passed to the SetInitialRow2 method?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Sorry I could not respond last night because I didn't have access to my laptop from where I was.
SetInitialRow() is called in page_load() event:
if (!Page.IsPostBack)
{
this.SetInitialRow();
...
...
}
}
SetInitialRow2() is called in populateRecord function:
private void PopulateRecord()
{
foreach (RepeaterItem item in Repeater1.Items)
{
string registerNumber = (item.FindControl("txtboatregNum") as TextBox).Text;
string bregisterNumber = (item.FindControl("cgaurdNumber") as TextBox).Text;
if (item.ItemIndex == 0)
{
this.SetInitialRow2(registerNumber, bregisterNumber);
}
else
{
AddNewRow2(registerNumber, bregisterNumber);
}
foreach (RepeaterItem Item in Repeater2.Items)
{
(Item.FindControl("BtnAdd2") as Button).Visible = Repeater2.Items.Count > 2;
(Item.FindControl("btnDelete2") as Button).Visible = Repeater2.Items.Count > 2;
}
}
}<pre>
which in turn is called by the NEXT button click event:
<pre>protected void OnClickNext(object sender, EventArgs e)
{
int rowIndex = 0;
if (ViewState["CurrTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrTable"];
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= Repeater1.Items.Count; i++)
{
TextBox tbboatregNum = (TextBox)Repeater1.Items[rowIndex].FindControl("txtboatregNum");
TextBox tbPayerret = (TextBox)Repeater1.Items[rowIndex].FindControl("txtPayerret");
TextBox tbCGvesselNum = (TextBox)Repeater1.Items[rowIndex].FindControl("cgaurdNumber");
TextBox tbCGtaxpayerret = (TextBox)Repeater1.Items[rowIndex].FindControl("cguardreturnedval");
dtCurrentTable.Rows[i - 1]["MarineRegNo"] = tbboatregNum.Text;
dtCurrentTable.Rows[i - 1]["TaxPyrRetdVal"] = tbPayerret.Text;
dtCurrentTable.Rows[i - 1]["VesselRegNo"] = tbCGvesselNum.Text;
dtCurrentTable.Rows[i - 1]["VesselTaxPyrRetdVal"] = tbCGtaxpayerret.Text;
rowIndex++;
}
ViewState["TempData"] = dtCurrentTable;
}
myMultiView.ActiveViewIndex += 1;
if (myMultiView.ActiveViewIndex != 3)
{
PopulateRecord();
}
}
}
So, clicking next is supposed to pass these values from Repeater1 to Repeater2.
There are also some other dependencies like getting the total value of TaxPyrRetdVal and VesselTaxPyrRetdVal but they are not relevant because once Repeater is able
to recognize MarineRegNo and VesselRegNo, the others become visible.
Then there are a couple of stored procedures that populate both SetInitialRow() and SetInitialRow2() datatables.
If you remove SetInitialRow2(), then there is no issues with passing the values from Repeater1 to Repeater2.
Only issue there is that the values for Repeater2 will not be passed, only those two form values, MarineRegNo and VesselRegNo are passed.
I must admit that I didn't do all of these by myself.
It is really very long and complicated code.
If I can figure out a way to check the dt datable table values before binding to Repeater, perhaps this could work.
Also, if I remove the stored procedures, everything will be populated on both repeaters except the two most important iems MarineRegNo and VesselRegNo.
I have been stuck on this now for days and was supposed to be demo'ing this app this morning.
Thanks sir as usual for all your expert assistance.
|
|
|
|
|
I'm not sure I'm following exactly what you're doing, but I'd be inclined to start by tidying up the code:
private DataTable LoadTable1(bool createIfMissing)
{
const string ViewStateKey = "CurrTable";
DataTable dt = ViewState[ViewStateKey] as DataTable;
if (createIfMissing)
{
if (dt == null)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("ID", typeof(string)));
dt.Columns.Add(new DataColumn("MarineRegNo", typeof(string)));
dt.Columns.Add(new DataColumn("TaxPyrRetdVal", typeof(string)));
dt.Columns.Add(new DataColumn("VesselRegNo", typeof(string)));
dt.Columns.Add(new DataColumn("VesselTaxPyrRetdVal", typeof(string)));
ViewState[ViewStateKey] = dt;
}
if (dt.Rows.Count == 0)
{
DataRow dr = dt.NewRow();
dr["ID"] = 1;
dr["MarineRegNo"] = string.Empty;
dr["TaxPyrRetdVal"] = string.Empty;
dr["VesselRegNo"] = string.Empty;
dr["VesselTaxPyrRetdVal"] = string.Empty;
dt.Rows.Add(dr);
}
}
return dt;
}
private void SetInitialRow()
{
myMultiView.ActiveViewIndex = 0;
DataTable dt = LoadTable1(true);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
private DataTable LoadTable2(bool createIfMissing)
{
const string ViewStateKey = "CurrentTable";
DataTable dt = ViewState[ViewStateKey] as DataTable;
if (dt == null && createIfMissing)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("boatcnty", typeof(string)));
dt.Columns.Add(new DataColumn("aRegNo", typeof(string)));
...
ViewState[ViewStateKey] = dt;
}
return dt;
}
private void PopulateRecord(DataTable table1)
{
DataTable table2 = LoadTable2(true);
table2.Rows.Clear();
foreach (DataRow row in table1.Rows)
{
DataRow dr = table2.NewRow();
dr["RowNumber"] = table2.Rows.Count + 1;
dr["aRegNo"] = row["MarineRegNo"];
dr["coastGuardNumber"] = row["VesselRegNo"];
...
table2.Rows.Add(dr);
}
Repeater2.DataSource = table2;
Repeater2.DataBind();
foreach (RepeaterItem item in Repeater2.Items)
{
((Button)item.FindControl("BtnAdd2")).Visible = table2.Rows.Count > 1;
((Button)item.FindControl("btnDelete2")).Visible = table2.Rows.Count > 1;
}
}
protected void OnClickNext(object sender, EventArgs e)
{
DataTable dt = LoadTable1(false);
if (dt != null)
{
if (dt.Rows.Count != 0)
{
int rowIndex = 0;
foreach (RepeaterItem item in Repeater1.Items)
{
switch (item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
case ListItemType.SelectedItem:
case ListItemType.EditItem:
{
TextBox tbboatregNum = (TextBox)item.FindControl("txtboatregNum");
TextBox tbPayerret = (TextBox)item.FindControl("txtPayerret");
TextBox tbCGvesselNum = (TextBox)item.FindControl("cgaurdNumber");
TextBox tbCGtaxpayerret = (TextBox)item.FindControl("cguardreturnedval");
DataRow row = dt.Rows[rowIndex];
row["MarineRegNo"] = tbboatregNum.Text;
row["TaxPyrRetdVal"] = tbPayerret.Text;
row["VesselRegNo"] = tbCGvesselNum.Text;
row["VesselTaxPyrRetdVal"] = tbCGtaxpayerret.Text;
rowIndex++;
break;
}
}
}
}
myMultiView.ActiveViewIndex += 1;
if (myMultiView.ActiveViewIndex != 3)
{
PopulateRecord(dt);
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 21-Sep-17 13:29pm.
|
|
|
|
|
Thank you very much Richard.
I think I got what you are trying to do but it is complaining about registerNumber assigned to ARegNo and bRegisterNumber assigned to coastGuardNumber.
The reason I am having this issue is because we want out users to be able to enter an account number and populate both Repeater1 and Repeater2 if record exists and the reason we want users to enter an account to populate those controls is because they have to complete a form but the form is too long.
So, we broke the form down into 4 pages with page 4 being preview page.
So, user can complete page one, click a button to save and continue later.
When they come back later, they want to know where they stopped.
I don't know if I am still making sense.
modified 21-Sep-17 13:02pm.
|
|
|
|
|
You'd still need to call SetInitialRow , but you shouldn't need to call SetInitialRow2 .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am just running into many bugs.
First, registerNumber which is assigned to ARegNo is not being recognized.
bregisterNumber which is assigned to coastGuardNumber is not being recorgnized.
Also, dr["ID"] = 1; on populateRecord function is not being recognized.
Thanks for your help sir.
|
|
|
|
|
Aside from a typo in the LoadTable2 function, where I was using dts instead of dt , there shouldn't be any compiler errors with the code I posted.
The code I posted doesn't contain either registerNumber or bregisterNumber .
And the PopulateRecord method I posted doesn't contain dr["ID"] = 1; anywhere.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That's true sir but the error came up because I added the rest of the code for SetInitialRow2() unless you asking me to use only the ones you posted.
If so, how do I handle the rest because they are supposed to populate Repeater2 when user enters an account number just like MarineRegNo and the other 3 that came with SetInitialRow()
Here is the complete code for SetInitialRow2(). I posted entire code yesterday.
Thanks so much for all your help.
private void SetInitialRow2(string registerNumber, string bregisterNumber)
{
DataTable dta;
if (ViewState["CurrentTable"] == null)
{
dta = new DataTable();
DataRow dr = null;
dta.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dta.Columns.Add(new DataColumn("boatcnty", typeof(string)));
dta.Columns.Add(new DataColumn("aRegNo", typeof(string)));
dta.Columns.Add(new DataColumn("aMake", typeof(string)));
dta.Columns.Add(new DataColumn("mMake", typeof(string)));
dta.Columns.Add(new DataColumn("ModelNoA", typeof(string)));
dta.Columns.Add(new DataColumn("ModelNoM", typeof(string)));
dta.Columns.Add(new DataColumn("boatYrBuilt", typeof(string)));
dta.Columns.Add(new DataColumn("motorYrBuilt", typeof(string)));
dta.Columns.Add(new DataColumn("blength", typeof(string)));
dta.Columns.Add(new DataColumn("hullmaterial", typeof(string)));
dta.Columns.Add(new DataColumn("mhorsepower", typeof(string)));
dta.Columns.Add(new DataColumn("rdlmhorsepType", typeof(string)));
dta.Columns.Add(new DataColumn("datePurchased", typeof(string)));
dta.Columns.Add(new DataColumn("mdatePurchased", typeof(string)));
dta.Columns.Add(new DataColumn("PurchaseType", typeof(string)));
dta.Columns.Add(new DataColumn("rblmPurchasedType", typeof(string)));
dta.Columns.Add(new DataColumn("PrevOnwerName", typeof(string)));
dta.Columns.Add(new DataColumn("prevAddr", typeof(string)));
dta.Columns.Add(new DataColumn("prevCity", typeof(string)));
dta.Columns.Add(new DataColumn("PrevState", typeof(string)));
dta.Columns.Add(new DataColumn("prevzip", typeof(string)));
dta.Columns.Add(new DataColumn("mPrevOnwerName", typeof(string)));
dta.Columns.Add(new DataColumn("mprevAddr", typeof(string)));
dta.Columns.Add(new DataColumn("mprevCity", typeof(string)));
dta.Columns.Add(new DataColumn("mPrevState", typeof(string)));
dta.Columns.Add(new DataColumn("mprevzip", typeof(string)));
dta.Columns.Add(new DataColumn("buyername", typeof(string)));
dta.Columns.Add(new DataColumn("buyeraddress", typeof(string)));
dta.Columns.Add(new DataColumn("buyercity", typeof(string)));
dta.Columns.Add(new DataColumn("buyerstate", typeof(string)));
dta.Columns.Add(new DataColumn("buyerzip", typeof(string)));
dta.Columns.Add(new DataColumn("datesold", typeof(string)));
dta.Columns.Add(new DataColumn("salePrice", typeof(string)));
dta.Columns.Add(new DataColumn("Description", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyername", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyeraddress", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyercity", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyerstate", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyerzip", typeof(string)));
dta.Columns.Add(new DataColumn("mdatesold", typeof(string)));
dta.Columns.Add(new DataColumn("msalePrice", typeof(string)));
dta.Columns.Add(new DataColumn("mDescription", typeof(string)));
dta.Columns.Add(new DataColumn("boatCost", typeof(string)));
dta.Columns.Add(new DataColumn("motorCost", typeof(string)));
dta.Columns.Add(new DataColumn("rblIssues", typeof(string)));
dta.Columns.Add(new DataColumn("functionalIsses", typeof(string)));
dta.Columns.Add(new DataColumn("mrblIssues", typeof(string)));
dta.Columns.Add(new DataColumn("mfunctionalIsses", typeof(string)));
dta.Columns.Add(new DataColumn("vesseltypeUse", typeof(string)));
dta.Columns.Add(new DataColumn("vesselname", typeof(string)));
dta.Columns.Add(new DataColumn("vessellength", typeof(string)));
dta.Columns.Add(new DataColumn("vesselYrBult", typeof(string)));
dta.Columns.Add(new DataColumn("VesselHullMateria", typeof(string)));
dta.Columns.Add(new DataColumn("vesselhorsepEngine", typeof(string)));
dta.Columns.Add(new DataColumn("coastGuardNumber", typeof(string)));
dta.Columns.Add(new DataColumn("VesselYrPurchased", typeof(string)));
dta.Columns.Add(new DataColumn("PurchasedNew", typeof(string)));
dta.Columns.Add(new DataColumn("VesselPurchaseAmt", typeof(string)));
dta.Columns.Add(new DataColumn("homePort", typeof(string)));
dta.Columns.Add(new DataColumn("whereDocked", typeof(string)));
dta.Columns.Add(new DataColumn("bmequipAccessoryList", typeof(string)));
dr = dta.NewRow();
dr["RowNumber"] = 1;
dr["boatcnty"] = string.Empty;
dr["ARegNo"] = registerNumber;
dr["aMake"] = string.Empty;
dr["mMake"] = string.Empty;
dr["ModelNoA"] = string.Empty;
dr["ModelNoM"] = string.Empty;
dr["boatYrBuilt"] = string.Empty;
dr["motorYrBuilt"] = string.Empty;
dr["blength"] = string.Empty;
dr["hullmaterial"] = string.Empty;
dr["mhorsepower"] = string.Empty;
dr["rdlmhorsepType"] = string.Empty;
dr["datePurchased"] = string.Empty;
dr["mdatePurchased"] = string.Empty;
dr["PurchaseType"] = string.Empty;
dr["rblmPurchasedType"] = string.Empty;
dr["PrevOnwerName"] = string.Empty;
dr["prevAddr"] = string.Empty;
dr["prevCity"] = string.Empty;
dr["PrevState"] = string.Empty;
dr["prevzip"] = string.Empty;
dr["mPrevOnwerName"] = string.Empty;
dr["mprevAddr"] = string.Empty;
dr["mprevCity"] = string.Empty;
dr["mPrevState"] = string.Empty;
dr["mprevzip"] = string.Empty;
dr["buyername"] = string.Empty;
dr["buyeraddress"] = string.Empty;
dr["buyercity"] = string.Empty;
dr["buyerstate"] = string.Empty;
dr["buyerzip"] = string.Empty;
dr["datesold"] = string.Empty;
dr["salePrice"] = string.Empty;
dr["Description"] = string.Empty;
dr["mbuyername"] = string.Empty;
dr["mbuyeraddress"] = string.Empty;
dr["mbuyercity"] = string.Empty;
dr["mbuyerstate"] = string.Empty;
dr["mbuyerzip"] = string.Empty;
dr["mdatesold"] = string.Empty;
dr["msalePrice"] = string.Empty;
dr["mDescription"] = string.Empty;
dr["boatCost"] = string.Empty;
dr["motorCost"] = string.Empty;
dr["rblIssues"] = string.Empty;
dr["functionalIsses"] = string.Empty;
dr["mrblIssues"] = string.Empty;
dr["mfunctionalIsses"] = string.Empty;
dr["vesseltypeUse"] = string.Empty;
dr["vesselname"] = string.Empty;
dr["vessellength"] = string.Empty;
dr["vesselYrBult"] = string.Empty;
dr["VesselHullMateria"] = string.Empty;
dr["vesselhorsepEngine"] = string.Empty;
dr["coastGuardNumber"] = bregisterNumber;
dr["VesselYrPurchased"] = string.Empty;
dr["PurchasedNew"] = string.Empty;
dr["VesselPurchaseAmt"] = string.Empty;
dr["homePort"] = string.Empty;
dr["whereDocked"] = string.Empty;
dr["bmequipAccessoryList"] = string.Empty;
dta.Rows.Add(dr);
}
else
{
dta = (DataTable)ViewState["CurrentTable"];
}
ViewState["CurrentTable"] = dta;
if (dta.Rows.Count > 0)
{
Repeater2.DataSource = dta;
Repeater2.DataBind();
}
}
|
|
|
|
|
Don't use SetInitialRow2 or AddNewRow2 .
Add the missing columns in the LoadTable2 method, where I've put "…"; and add the missing row values in the PopulateRecord method, where I've put "…".
LoadTable2 will create the table if it doesn't exist, and store it in the view-state. PopulateRecord will create the rows in that table based on the other table, and bind Repeater2 to the result. The SetInitialRow2 and AddNewRow2 methods aren't needed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You are such a genius!
This is incredible. You did all of this in a few minutes something I have been struggling with for days.
Even though I have not added all the records to PopulateRecord method, it is already beginning to populate MarineRegNo and the others to form.
Please bear with me for a few more questions.
On the LoadTable2 method, I am still getting error that registerNumber and bregisterNumber do not exist.
I will post entire LoadTable2 so you can tell me if I need to take that portion out.
private DataTable LoadTable2(bool createIfMissing)
{
const string ViewStateKey = "CurrentTable";
DataTable dt = ViewState[ViewStateKey] as DataTable;
if (dt == null && createIfMissing)
{
dt = new DataTable();
dta.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dta.Columns.Add(new DataColumn("boatcnty", typeof(string)));
dta.Columns.Add(new DataColumn("aRegNo", typeof(string)));
dta.Columns.Add(new DataColumn("aMake", typeof(string)));
dta.Columns.Add(new DataColumn("mMake", typeof(string)));
dta.Columns.Add(new DataColumn("ModelNoA", typeof(string)));
dta.Columns.Add(new DataColumn("ModelNoM", typeof(string)));
dta.Columns.Add(new DataColumn("boatYrBuilt", typeof(string)));
dta.Columns.Add(new DataColumn("motorYrBuilt", typeof(string)));
dta.Columns.Add(new DataColumn("blength", typeof(string)));
dta.Columns.Add(new DataColumn("hullmaterial", typeof(string)));
dta.Columns.Add(new DataColumn("mhorsepower", typeof(string)));
dta.Columns.Add(new DataColumn("rdlmhorsepType", typeof(string)));
dta.Columns.Add(new DataColumn("datePurchased", typeof(string)));
dta.Columns.Add(new DataColumn("mdatePurchased", typeof(string)));
dta.Columns.Add(new DataColumn("PurchaseType", typeof(string)));
dta.Columns.Add(new DataColumn("rblmPurchasedType", typeof(string)));
dta.Columns.Add(new DataColumn("PrevOnwerName", typeof(string)));
dta.Columns.Add(new DataColumn("prevAddr", typeof(string)));
dta.Columns.Add(new DataColumn("prevCity", typeof(string)));
dta.Columns.Add(new DataColumn("PrevState", typeof(string)));
dta.Columns.Add(new DataColumn("prevzip", typeof(string)));
dta.Columns.Add(new DataColumn("mPrevOnwerName", typeof(string)));
dta.Columns.Add(new DataColumn("mprevAddr", typeof(string)));
dta.Columns.Add(new DataColumn("mprevCity", typeof(string)));
dta.Columns.Add(new DataColumn("mPrevState", typeof(string)));
dta.Columns.Add(new DataColumn("mprevzip", typeof(string)));
dta.Columns.Add(new DataColumn("buyername", typeof(string)));
dta.Columns.Add(new DataColumn("buyeraddress", typeof(string)));
dta.Columns.Add(new DataColumn("buyercity", typeof(string)));
dta.Columns.Add(new DataColumn("buyerstate", typeof(string)));
dta.Columns.Add(new DataColumn("buyerzip", typeof(string)));
dta.Columns.Add(new DataColumn("datesold", typeof(string)));
dta.Columns.Add(new DataColumn("salePrice", typeof(string)));
dta.Columns.Add(new DataColumn("Description", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyername", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyeraddress", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyercity", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyerstate", typeof(string)));
dta.Columns.Add(new DataColumn("mbuyerzip", typeof(string)));
dta.Columns.Add(new DataColumn("mdatesold", typeof(string)));
dta.Columns.Add(new DataColumn("msalePrice", typeof(string)));
dta.Columns.Add(new DataColumn("mDescription", typeof(string)));
dta.Columns.Add(new DataColumn("boatCost", typeof(string)));
dta.Columns.Add(new DataColumn("motorCost", typeof(string)));
dta.Columns.Add(new DataColumn("rblIssues", typeof(string)));
dta.Columns.Add(new DataColumn("functionalIsses", typeof(string)));
dta.Columns.Add(new DataColumn("mrblIssues", typeof(string)));
dta.Columns.Add(new DataColumn("mfunctionalIsses", typeof(string)));
dta.Columns.Add(new DataColumn("vesseltypeUse", typeof(string)));
dta.Columns.Add(new DataColumn("vesselname", typeof(string)));
dta.Columns.Add(new DataColumn("vessellength", typeof(string)));
dta.Columns.Add(new DataColumn("vesselYrBult", typeof(string)));
dta.Columns.Add(new DataColumn("VesselHullMateria", typeof(string)));
dta.Columns.Add(new DataColumn("vesselhorsepEngine", typeof(string)));
dta.Columns.Add(new DataColumn("coastGuardNumber", typeof(string)));
dta.Columns.Add(new DataColumn("VesselYrPurchased", typeof(string)));
dta.Columns.Add(new DataColumn("PurchasedNew", typeof(string)));
dta.Columns.Add(new DataColumn("VesselPurchaseAmt", typeof(string)));
dta.Columns.Add(new DataColumn("homePort", typeof(string)));
dta.Columns.Add(new DataColumn("whereDocked", typeof(string)));
dta.Columns.Add(new DataColumn("bmequipAccessoryList", typeof(string)));
ViewState[ViewStateKey] = dta;
}
if (dta.Rows.Count == 0)
{
DataRow dr = dta.NewRow();
dr["RowNumber"] = 1;
dr["boatcnty"] = string.Empty;
dr["ARegNo"] = registerNumber;
dr["aMake"] = string.Empty;
dr["mMake"] = string.Empty;
dr["ModelNoA"] = string.Empty;
dr["ModelNoM"] = string.Empty;
dr["boatYrBuilt"] = string.Empty;
dr["motorYrBuilt"] = string.Empty;
dr["blength"] = string.Empty;
dr["hullmaterial"] = string.Empty;
dr["mhorsepower"] = string.Empty;
dr["rdlmhorsepType"] = string.Empty;
dr["datePurchased"] = string.Empty;
dr["mdatePurchased"] = string.Empty;
dr["PurchaseType"] = string.Empty;
dr["rblmPurchasedType"] = string.Empty;
dr["PrevOnwerName"] = string.Empty;
dr["prevAddr"] = string.Empty;
dr["prevCity"] = string.Empty;
dr["PrevState"] = string.Empty;
dr["prevzip"] = string.Empty;
dr["mPrevOnwerName"] = string.Empty;
dr["mprevAddr"] = string.Empty;
dr["mprevCity"] = string.Empty;
dr["mPrevState"] = string.Empty;
dr["mprevzip"] = string.Empty;
dr["buyername"] = string.Empty;
dr["buyeraddress"] = string.Empty;
dr["buyercity"] = string.Empty;
dr["buyerstate"] = string.Empty;
dr["buyerzip"] = string.Empty;
dr["datesold"] = string.Empty;
dr["salePrice"] = string.Empty;
dr["Description"] = string.Empty;
dr["mbuyername"] = string.Empty;
dr["mbuyeraddress"] = string.Empty;
dr["mbuyercity"] = string.Empty;
dr["mbuyerstate"] = string.Empty;
dr["mbuyerzip"] = string.Empty;
dr["mdatesold"] = string.Empty;
dr["msalePrice"] = string.Empty;
dr["mDescription"] = string.Empty;
dr["boatCost"] = string.Empty;
dr["motorCost"] = string.Empty;
dr["rblIssues"] = string.Empty;
dr["functionalIsses"] = string.Empty;
dr["mrblIssues"] = string.Empty;
dr["mfunctionalIsses"] = string.Empty;
dr["vesseltypeUse"] = string.Empty;
dr["vesselname"] = string.Empty;
dr["vessellength"] = string.Empty;
dr["vesselYrBult"] = string.Empty;
dr["VesselHullMateria"] = string.Empty;
dr["vesselhorsepEngine"] = string.Empty;
dr["coastGuardNumber"] = bregisterNumber;
dr["VesselYrPurchased"] = string.Empty;
dr["PurchasedNew"] = string.Empty;
dr["VesselPurchaseAmt"] = string.Empty;
dr["homePort"] = string.Empty;
dr["whereDocked"] = string.Empty;
dr["bmequipAccessoryList"] = string.Empty;
dta.Rows.Add(dr);
}
return dta;
}
The second question I have is that I see how you assigned values to MarineRegNo and VesselRegNo.
dr["RowNumber"] = table2.Rows.Count + 1;
dr["aRegNo"] = row["MarineRegNo"];
dr["coastGuardNumber"] = row["VesselRegNo"];
Do I need to assign values from the DB to the rest like instead of this:
dr["boatcnty"] = string.Empty;
I do this:
dr["boatcnty"] = row["boatcnty"];
row["boatcnty"] is db record.
Thanks so much Richard.
|
|
|
|
|
In LoadTable2 , take out the entire if (dta.Rows.Count == 0) { ... } block. The rows are created in the PopulateRecord function, based on the rows from the other table.
Whether or not you assign values to the empty columns in the new rows depends on how you're using those columns. If you don't assign a value, the default will be null . If you try to access the length of a value that's null , you'll get a NullReferenceException . But if all you're doing is binding the data using Bind or Eval , setting the column to string.Empty won't make any difference.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ok, got it.
Almost there but still have a couple more questions.
1, I didn't get a response to the registerNumber and bregisterNumber fields in the LoadTable2 method.
They are giving errors that they don't exist.
Finally, another method is giving me errors.
The
private void SetPreviousData2(string registerNumber, string bregisterNumber)
When called below, is giving errors that SetPreviousData2 must have a return type.
SetPreviousData2(registerNumber, bregisterNumber);
Do I need to get rid of those as well?
If I do get rid of that method, then when I click NEXT to go to page2, it is blank.
modified 21-Sep-17 16:30pm.
|
|
|
|
|