|
No, using Eval with one argument and expecting a string was a mistake,
the problem was he did not understand the compiler's error message which pointed to the following lines, not the line that was in conflict with his intentions, and which was not only late but also not as clear as one might hope, both effects due to the usage of var .
If he had written:
string Buyernames = Eval("buyername");
the compiler would have flagged THAT line, not the following ones, with a clearer message, something like "cannot implicitly convert type 'object' to string"; which everyone understands.
So: remove var , and you'll have no problem fixing the mistake.
|
|
|
|
|
Brent Jenkins wrote: Nothing wrong with using
var There is when you know what the type is.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
SerenityNowDev wrote: There is when you know what the type is.
What's better here then?
System.String myWonderfulString = new System.String();
or..
var myWonderfulString = new System.String();
Or what about your own libraries?
Code.Project.Sample.Library.Helpers.DemoToShowHowDaftThisIs myClassInstance = new Code.Project.Sample.Library.Helpers.DemoToShowHowDaftThisIs();
or..
var myClassInstance = new Code.Project.Sample.Library.Helpers.DemoToShowHowDaftThisIs();
Personally, I really hate typing/reading the same thing twice in the same line. Personally, I really hate typing/reading the same thing twice in the same line.
Now is it bad enough that you let somebody else kick your butts without you trying to do it to each other? Now if we're all talking about the same man, and I think we are... it appears he's got a rather growing collection of our bikes.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
SerenityNowDev wrote: There is when you know what the type is.
Are you missing a "don't" from that sentence?
var foo = new { Key = 42, Text = "The answer" };
var cache = new Dictionary<Foo, Bar>();
var groupedList = contacts.GroupBy(c => c.Company);
var lookup = (IDictionary<Foo, Bar>)new Dictionary<Foo, Bar>();
var bar = Wibble();
var s = "Hello";
Or were you suggesting that var should only ever be used for anonymous types?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Or were you suggesting that var should only ever be used for anonymous types? I was suggesting not to overuse it, as a previous responder also said.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Eval(expression) returns an object . Try Eval(expression, format) instead, which returns a string.
You'll also need to account for cases where the name doesn't contain a space.
string buyername = Eval("buyername", "{0}");
string bFName, bLName;
int index = buyername.IndexOf(' ');
if (index == -1)
{
bFName = string.Empty;
bLName = buyername;
}
else
{
bFName = buyername.Substring(0, index);
bLName = buyername.Substring(index + 1);
}
Falsehoods Programmers Believe About Names | Kalzumeus Software[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
As usual, perfect solution!
Thank you very much sir.
If I could sir, can please cheat a bit here?
I have similar issue, same code where that same Eval is presenting problem for me.
I have this markup:
bel ID="lblPurchType" Text='<%#Eval("rblPurchaseType") %>' runat="server" />
I am trying to referencing in C# so I can insert records into the database:
Does this look right?
cmd2.Parameters.AddWithValue("@ptype", Eval("rblPurchaseType","rblPurchaseType"));
|
|
|
|
|
No. The format parameter is the same string you'd pass to String.Format[^], with a single placeholder representing the value returned from the data source.
Eval("rblPurchaseType","rblPurchaseType") will literally return the string "rblPurchaseType" , since there is no placeholder in the format parameter.
If you wanted to return the value of the field as a string, you'd need: Eval("rblPurchaseType", "{0}")
But since the AddWithValue method takes an object, you'd be better off using the overload that doesn't convert the value to a string:
cmd2.Parameters.AddWithValue("@ptype", Eval("rblPurchaseType"));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ahhhh!
I will try with the "{0}"
I had tried the second option before posting here the first time and it did not work.
This:
d2.Parameters.AddWithValue("@ptype", Eval("rblPurchaseType"));
Maybe I did something wrong.
Thanks very much.
UPDATE: Tried both options but still end up with following error message:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
modified 18-Aug-17 15:16pm.
|
|
|
|
|
samflex wrote: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
If you're doing this from the code-behind, you'll need to be in a DataBinding event handler for your data-bound control. Otherwise, ASP.NET has no idea where you want to get the data from.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
please tell me anything new exist to test EF repository instead of Mock lib in .Net Core.
if possible please share some good article links. thanks
|
|
|
|
|
Mou_kol wrote: good article links Google is the place to find them.
|
|
|
|
|
how can I use rich textbox in web application without using third part
|
|
|
|
|
It entirely depends on what you want to build, what framework you are using and how much do you know about a Rich Text Box. Since, you have asked this under ASP.NET, I can tell you that HTML can be used to build a basic RichTextBox here,
<div contenteditable="true">
Some content here, it can be edited with the support of CTRL B and CTRL I modifiers.
</div> You can try that code in any online fiddle, and see that the element would allow users to modify the content, through the use of CTRL + B and CTRL + I etc. Secondly, in ASP.NET there are some built-in text boxes, but they are not rich one, thus you would require to use a third-party, Rich Text box in asp.net | The ASP.NET Forums. It depends on how much effort you want to put into this project of yours.
As I mentioned, if you want to build a complex text editor, consider using one of the famous text editors out there instead of building your own text editor — rich text editors, and text editors online are quite similar, Google WYSIWYG for instance; TinyMCE | The Most Advanced WYSIWYG HTML Editor.
Making content editable - Web developer guides | MDN
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hey guys, as of recent i have been learning ASP so i can create a web application for an existing SQL database. I'm just wondering how i could go about creating user login/logout , sessions , profile page , and registration pages. Im developing in visual studio community 2017.
Thanks.
|
|
|
|
|
Go to ASP.NET | The ASP.NET Site[^] where you will find plenty of tutorials and samples. For anything you do not find you should use Google.
|
|
|
|
|
Hello again.
This is the last installment of my project.
was using Gridview1_RowDeleting with similar code below to delete a dynamically generated row.
That worked great.
Now, I am trying to use the code below to accomplish similar function only this time, with Repeater control.
I can't get past int rowID = e.RowIndex.
Any ideas how to work around this?
Markup:
<asp:Button ID="btnDelete" runat="server" Width="70"
Text="Remove" CommandName="Remove"
CommandArgument='<%# Container.ItemIndex %>' />
I have also tried this:
sp:Button ID="btnDelete" Style="width: 120px;" runat="server" Text="Remove a row"
OnClick="btnDelete_Click" CssClass="btnclass" />
C#
otected void btnDelete_Click(object sender, EventArgs e)
{
int rowIndex = 0;
int rowID = e.RowIndex;
lblTotal.Text = "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]["boatregNum"] = tbboatregNum.Text;
dtCurrentTable.Rows[i - 1]["taxpayerret"] = tbPayerret.Text;
dtCurrentTable.Rows[i - 1]["CGvesselNum"] = tbCGvesselNum.Text;
dtCurrentTable.Rows[i - 1]["CGtaxpayerret"] = tbCGtaxpayerret.Text;
rowIndex++;
}
if (e.RowIndex < dtCurrentTable.Rows.Count)
{
dtCurrentTable.Rows.Remove(dtCurrentTable.Rows[rowID]);
}
}
ViewState["CurrTable"] = dtCurrentTable;
Repeater1.DataSource = dtCurrentTable;
Repeater1.DataBind();
}
SetPreviousData();
}
Many thanks in advance
|
|
|
|
|
Where have you seen that EventArgs has an RowIndex property?
The moment you moved from Grid to Repeater you lost all the help. Repeater does not maintain a table-like structure, every block created from the template stands on its own...
That's the reason you have to pass identifying parameters to the template, like CommandArgument='<%# Container.ItemIndex %>'... Use that to find the row to remove!
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Kornfield,
Thanks for your response.
Just so I understand your point, you are saying that if I use the following:
sp:Button ID="btnDelete" runat="server" Width="70"
Text="Remove" CommandName="Remove"
CommandArgument='<%# Container.ItemIndex %>' /> ,
then I would be able to use the C# with rowIndex as is?
|
|
|
|
|
No!!!
What I'm saying, that you have no way to use a property that does not exist on the object, but you can fill in the gap by passing the value on the CommandArgument property of the button initiated the event...
So instead of e.RowIndex you can use btnDelete.CommandArgument...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I have figured it out.
Thank you.
|
|
|
|
|
Hi
I ran the fortify scan to see if we have any vulnerabilities and found some of them wrt cross site scripting poor validation on the .aspx pages. Tried the below following methods to solve but still Fortify shows as vulnerability.
Here's my code.
<asp:label id="lblCsf" runat="server" text="<%# AntiXss.AntiXssEncoder.HtmlEncode(Eval("Max").ToString, True) %>">
<asp:label id="lblCsf" runat="server" text="<%# HttpUtility.HtmlEncode(Eval("Max")) %>">
Appreciate if any of you can suggest some solution for this scenario.
|
|
|
|
|
|
Thanks for your response, but initially it was : and since fortify was showing as cross site vulnerability so I have changed to use AntiXss. But still it shows the same vulnerability. The only difference was while using : , it says Cross site vulnerability and when using AntiXss, it says Poor cross site vulnerability.
|
|
|
|
|
Still sounds like a bug in Fortify to me.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|