|
I cannot work out how to get an integer value from a textbox from inside a datalist for a variable to insert into SQL.
Here is my code.
<pre lang="c#">int qty = int.parse(dlProducts.Controls[0].FindControl("txtProductQty"));</pre>
and this variable will be put into an insert Query.
into a textbox inside a datalist id="dlProducts"
<pre lang="HTML"><pre lang="HTML"></pre><asp:TextBox ID="txtPeight="22px" Width="15px"></asp:TextBox></pre>
-- modified 14-Nov-12 16:21pm.
|
|
|
|
|
Hi,
I can't understand what your trying to do?.
but this is what i think you r trying to do.. u have a datalist control who has a child control which has a value and u need to retrieve it.
you r going fine except that your trying to send an asp.net textbox control to be parsed as int..
TextBox t=(TextBox)dlProducts.Controls[0].FindControl('txtexamp1');
[Explicit casting required]
int qty=int.parse(t.Text);
u will have the value which u can input in Sql.
I hope this answer helps u.
<div class="signature">rajeshkasani05</div>
|
|
|
|
|
using int qty=int.parse(t.Text); produces a formatException.
|
|
|
|
|
hi,
The format Exception may be thrown because you are not receiving any value or the string from the t.Text may be "" (empty string).please try to debug and check the issue or place your code snippet and let me check it.
Regards,
rajeshkasani05
|
|
|
|
|
My code is in the first message. The user will only be entering integers not string into the text box.
|
|
|
|
|
Do not use Int32.Parse() when you do not know the contents of the input. Use the Int32.TryParse() Method[^], or put the parsing code within a try/catch block. You should also use your debugger to check the value that the code is actually trying to interpret; don't assume it's the value that you think is there.
One of these days I'm going to think of a really clever signature.
|
|
|
|