I want to set my Salary field value into $23,000.00 and send that value into my database ,i created below code inside my model class but it has some errors need some one help to fix that errors,I am new to Asp.net MVC4 Please help me to solve that problems.
when i save data it goes to database like that way- $23000
but actually i want to send like that way -$23,000.00
when i view my results in my view page it seems $$23000
But i want that way - $23,000.00
Please help me to solve that problems.
Thanks .
public string Salary
{
get
{
return SalaryFormat;
}
set
{
StringBuilder sb = new StringBuilder();
SalaryFormat = Convert.ToString(sb.AppendFormat("${0: #,###.00}", value));
//SalaryFormat = value;
}
}
Thanks!
Related
Currently i am stucked in one point that when the customer completes its registration process what i want to do is Create a SeName from customers email address and store it in UrlRecord Table so that i can enable navigation to customers profile page. Below is the code that i had tried till now.
string CustomerSeName = "";
var CustomerModel=_customerService.GetCustomerById(_workContext.CurrentCustomer.Id);
if (CustomerModel != null)
{
CustomerSeName = customer.ValidateSeName(CustomerSeName, CustomerModel.Email, true);
_urlRecordService.SaveSlug(CustomerModel, CustomerSeName, 0);
}
in above code i am getting all the value in CustomerModel and CustomerSeName but when it executes SaveSlug() method it throws an Object reference not set error. I dont know which value it missing.Please help me out if someone knows the solution. Thanks in advance..!
I tried your code and couldn't compile.
After adding ISlugSupported to Customer entity and using this code all worked
private void GenerateCurrentCustomerSlug()
{
var slug = _workContext.CurrentCustomer.ValidateSeName(seName: "", name: _workContext.CurrentCustomer.Email, ensureNotEmpty: true);
_urlRecordService.SaveSlug(_workContext.CurrentCustomer, slug, languageId: 0);
}
The above code also works if there is no email set for current customer.
while trying to get data from https://blockchain.info/ticker in my grid view, i'm finding the result in single coloumn whether i want it in different coloumn.
i'm showing you my code and please give me a soloution.
public void ticker()
{
WebClient webClient = new WebClient();
dynamic result =webClient.DownloadString("https://blockchain.info/ticker");
GridView1.DataSource = result;
GridView1.DataBind();
}
[https://i.stack.imgur.com/nPjgS.jpg]
It looks like your results in JSON format so you have to convert in the proper format to display well in GridView.
import Newtonsoft.Json
dynamic result =JsonConvert.DeserializeObject(
webClient.DownloadString("https://blockchain.info/ticker"));
I hope it's help you, you can search more about it
thanks
I have hit a small issue and hoping someone might be able to assist. I am using a panel - On the page load, it should list all the products as no category has been selected as per stored procedure (this works perfectly).
When a user clicks on a specific category, it should only show the products that have the specific CategoryID. When I run the code in SQL, it works a dream for this part too, so assume the stored procedure is ok.
At
CategoryID = CategoryID
in GetProducts, I get
Warning: Assignment made to same variable; did you mean to assign something else?
However I am following a tutorial video and this works fine. Is there another silly error that is preventing it from working?
I think I have included all the required code - sorry if its a bit overkill!!
Thanks as ever in advance - Jack
Code behind pnlCategories:
private void GetProducts(int CategoryID)
{
ShoppingCart k = new ShoppingCart();
{
CategoryID = CategoryID;
};
Error identified - additional ";" added at following line:
ShoppingCart k = new ShoppingCart();
Code now reads
ShoppingCart k = new ShoppingCart()
{
CategoryID = CategoryID
};
and functions as expected!
that looks like a c# error and not a SQL Server error.
The problem is here in your GetProducts method. CategoryID = CategoryID;
C# is case sensitive. If you check your tutorial carefully, one of these will probably be lower case. Make sure you type that carefully.
try code change below and see where the compiler complains.
CategoryID = categoryID;
private void GetProducts(int CategoryID)
{
ShoppingCart k = new ShoppingCart();
{
CategoryID = CategoryID;
};
dlProducts.DataSource = null;
dlProducts.DataSource = k.GetProdcuts();
dlProducts.DataBind();
}
Good Afternoon Developers,
This is my function to generate the crystal Report,This will take the Report Name and ReportQuery as a input parameter and will generate a dataset , With this dataset how can i design my Report??Because this is Generated at the runtime , How can i access that to generate my ReportDesign??
public void fnLoadDataToReport(string rptName, string rptQuery)
{
try
{
DataSet myDS=new DataSet();
// crReportDocument.Load(Server.MapPath("Reports\" & RptName), OpenReportMethod.OpenReportByTempCopy);
crReportDocument.Load(Server.MapPath("Reports\\" + rptName ));
SqlConnection myConnection=new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ConnectionString);
SqlCommand myCommand=new SqlCommand(rptQuery,myConnection);
SqlDataAdapter MyDA=new SqlDataAdapter(myCommand);
MyDA.Fill(myDS,"ReportTable");
crReportDocument.SetDataSource(myDS);
crvReportGeneration.ReportSource=crReportDocument;
crvReportGeneration.ShowFirstPage();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
Any help is appreciable....!
All you need is an XML schema definition of the Dataset to be able to design the report. this can be achieved by the following code.
private void WriteSchemaToFile(DataSet thisDataSet){
// Set the file path and name. Modify this for your purposes.
string filename="mySchema.xml";
// Write the schema to the file.
thisDataSet.WriteXmlSchema(filename);
}
now add the above created file to your project.
Now while designing the report select Database expert and select the xml file under Project. and add it (just like you add tables or views).
Now you are good to go. The rest of the steps are same.
Just make sure the name of the XSD schema and the table name in your Dataset match exactly.
Why are using DataSet as the source for the report. Instead of that if you use a stored procedure as the source, it will solve your problem and also maintenance will be much more easier
how can i get a form field id after submitting the form. im trying like this:
ViewData.TemplateInfo.GetFullHtmlFieldId(logOnParts.Part.UserNameOrEmail)
but no work on controller side. i need to get "Part_UserNameOrEmail" something..
if (String.IsNullOrEmpty(logOnParts.Part.UserNameOrEmail))
{
ModelState.AddModelError("Part_UserNameOrEmail", "error");
TempData["logon-focus-field"] = "Part_UserNameOrEmail";
}
so i will focus the field on view side like this:
$(document).ready(function () {
$('#TempData["logon-focus-field"]').focus();
});
A controller should absolutely not need such information. The generated id is a view specific information. If you need this in a controller this simply means that you have some serious design problem with your application. Unfortunately as you haven't explained your scenario in the question it is difficult to help you solving this problem. So in your controller you could do this:
Expression<Func<MyViewModel, string>> expression = x => x.Part.UserNameOrEmail;
string name = ExpressionHelper.GetExpressionText(expression);
string id = new TemplateInfo().GetFullHtmlFieldId(name);