|
When I use the above code I get the following error:
CS0165: Use of unassigned local variable 'lb2'
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
try
Label lb2 = new Label();
TextBox tb2 = new TextBox();
foreach (Control c in PlaceHolder2.Controls)
{...
|
|
|
|
|
OK thanks
That now has got rid of the error. The problem is the sql statement doesnt do anything. If I hard code the value in for the label and the line of code for the label out it works. Seems weird, as if the format of the label is not correct.
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
The problem appears to be with the if statement. If I use label in the if statement and hardcode the textbox value it works and if I use the textbox in the if statement and hardcode the label it also works. it seems that I cant find the label and textbox values if Im using the if statement below, is there a way around it?
thanks so far
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
if you know the ID of the label and the textbox, the best solution will probably be this:
Lable lb2 = (Lable)PlaceHolder2.FindControl("lb2");
TextBox tb2 = (TextBox)PlaceHolder2.FindControl("tb2");
if(lb2 != null && tb2 != null)
{
SqlCommand cmdinsertliftunion = new SqlCommand("INSERT INTO table(field1, field2) VALUES ('" + lb2.Text + "', '" + tb2.Text + "')", con);
cmdinsert.ExecuteNonQuery();
}
If you have multiple lables and textboxes in the placeholder and you don't know how many pairs of them you have.
Then you probably need to make all of this in another way. I would recommand that you add a DataGrid to the placeholder and in the
DataGrid you add pairs of lable and textbox. Then the code would look something like this.
DataGrid dg = (DataGrid)PlaceHolder2.FindControl("dgTheDataGrid");
foreace(DataGridItem dgi in dg.Items)
{
Lable lb2 = (Lable)dgi.FindControl("lb2");
TextBox tb2 = (TextBox)dgi.FindControl("tb2");
if(lb2 != null && tb2 != null)
{
SqlCommand cmdinsertliftunion = new SqlCommand("INSERT INTO table(field1, field2) VALUES ('" + lb2.Text + "', '" + tb2.Text + "')", con);
cmdinsert.ExecuteNonQuery();
}
}
modified on Wednesday, October 8, 2008 9:20 AM
|
|
|
|
|
Thanks for the reply, i will try that and then get back to you.
For the record I didnt downvote your posts I have actually been responding to you and trying your solutions.
Just ignore J4amiec hes just on a power trip
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
thomasa wrote: Lable lb2 = (Lable)dgi.FindControl("lb2");
TextBox tb2 = (TextBox)dgi.FindControl("tb2");
But if I use this will I not need to know the ID of the label and textbox?
Thats the problem I have is trying to give them an ID as there could be a lot of them which are all created on the fly.
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Yes, this would requier that you know the id.
That's way I suggested that you add a DataGrid where each row(DataGridItem) would contain 1 Label and 1 Textbox
|
|
|
|
|
Sorry, dident see the dgi.
That is acculy not a problem, for in each datagriditem every label would have the id="lb2".
as in:
DataGrid dg = new DataGrid();
dg.ID = "dgTheDataGrid";
dg.RunatServer = true;
DataGridItem dgi = new DataGridItem();
Lable lb2 = new Label();
lb2.ID = "lb2";
dgi.AddControl(lb2);
dg.AddControl(dgi);
PlaceHolder2.AddControl(dg);
The syntax in this code is probably wrong, but something like this.
|
|
|
|
|
Thanks for the reply again.
Im finding an error with the line DataGridItem dgi = new DataGridItem();
It says that: No overload for method 'DataGridItem' takes '0' arguments
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Someone provided me with help on another forum so I have some code which works now:
Thanks for all the help though!
foreach (Control c in PlaceHolder2.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
{
int textboxId = PlaceHolder2.Controls.IndexOf(c);
if (textboxId > 0)
{
Control cLabel = PlaceHolder2.Controls[textboxId - 1];
try
{
Label lb2 = (Label)cLabel;
TextBox tb2 = (TextBox)c;
SqlCommand cmdinsert = new SqlCommand("INSERT INTO table(field1, field2) VALUES ('" + lb2.Text + "', '" + tb2.Text + "')", con);
cmdinsert.ExecuteNonQuery();
cmdinsertliftunion.ExecuteNonQuery();
}
catch (Exception)
{
}
}
}
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Quite why this response got downvoted I dont know, but im voting it 4 as a (reasonably) good answer.
To .netman: this is not the first time ive seen good responses to your questions downvoted. Last time you said it wasnt you that downvoted, but this is too much of a coincidence! I suggest you are downvoting answers where you either dont like or dont understand the answer given. Therefore, for the time being at least I will personally not be answering any of your questions.
|
|
|
|
|
J4amieC wrote: Last time you said it wasnt you that downvoted, but this is too much of a coincidence!
Someone has downvoted some of my responses so I suggest you find out who that is and then you will find out who downvoted the other post.
J4amieC wrote: I suggest you are downvoting answers where you either dont like or dont understand the answer given.
You can suggest but you are wrong
J4amieC wrote: Therefore, for the time being at least I will personally not be answering any of your questions.
Considering your answer yesterday to one of my posts was a sarcastic 'go and read a beginners tutorial' and then you deleted it once I had quoted from it so frankly I couldnt care what you do
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
.netman wrote: Considering your answer yesterday to one of my posts was a sarcastic 'go and read a beginners tutorial'
Far from being sarcastic it was 100% serious. Your inital question on that day indicated you were unsure how to enumerate an arraylist of items. If that is giving you trouble you do indeed need a beginner's book (which is what i suggested). Everyone has to start somewhere.
|
|
|
|
|
An example tutorial for an arraylist closely applied to my situation was what I was looking for. Not a pure beginners book on asp.net which is what you suggested.
Oh well this is a pointless arguement as we clearly have totally different opinions on the siutation.
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
.netman wrote: An example tutorial for an arraylist closely applied to my situation was what I was looking for.
You seem to be having memory problems, here i'll quote your original question from yesterday:
"I have an arraylist which contains a number of items.
What is the best way to go through the items in the list.
ANy good tutorials on looping through the arraylist."
If that isn't screaming "beginning programming book" then its beyond me what is.
|
|
|
|
|
J4amieC wrote: You seem to be having memory problems,
Your're the only problem around here
J4amieC wrote: If that isn't screaming "beginning programming book" then its beyond me what is.
Yes but your reply(which you deleted to cover your back) just suggested to go get a beginners asp.net book rather than actually suggesting a proper tutorial.
You seem to be downvoting my posts as well which makes you a hyporcrite and confirms my suspicions that you are a complete moron.
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
.netman wrote: Yes but your reply(which you deleted to cover your back)
Wrong again chump, go check again its still there.
Idiot.
|
|
|
|
|
Deleted Message
You really are dumb
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
.netman wrote: if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
The above line is awful use the is (or as) keyword.
if(c is TextBox)
{
}
or
TextBox tb = c as TextBox
if(tb != null)
{
}
Also, as was correctly stated above, you need to check if 'c' is a Label as well. Note that these 2 controls both implement ITextControl which has a .Text property that you can use.
This will be my final answer to your questions. see above response for why.
modified on Wednesday, October 8, 2008 8:38 AM
|
|
|
|
|
Hi! EveryOne
I have a some problem.
My assignment is that I would design an Employee Id Card with database in ASP.Net. My requirement is when I run the program, Employee Information Form has appeared. After the submission of details all information is set on id card with employee photographs and stored in database as well.
I am a fresher. I stored all the information in database, but I don't know how set all the deails on Id card.
Please help me on this.
Thanks in advance.
|
|
|
|
|
Read all the information from the form/database and set it on the IDCard page.If it doesn't solve your issue then please give detail about the ID card.
Cheers!!
Brij
|
|
|
|
|
Thanks for your Kind attention!
As u know I am fresher in dot net and i don't know what's the process to set details in Id Form.
Id details are following:
NAME:
CODE:
EMP_PIC:
LOGO
ABOVE 4 ITEMS ARE SET ON FRONT SIDE OF CARD.
ADDRESS:
CONTACT NO:
SIGNATURE: (PLACE FOR SCANNED EMPLOYEE SIGNATURE)
TERMS & CONDITION:
ABOVE 4 ITEMS ARE SET ON BACK SIDE OF CARD.
SIR,IF U HAVE INTERESTED IN MY ASSIGNMENT, I WILL SEND MY ID FORMAT ON YOUR MAIL.
MY EMAIL ID: great_238@yahoo.co.in
THANKS
|
|
|
|
|
How can I create a sitemap from a database? I want to display menu as per allocated to user...I have User Types that determines what users can access
|
|
|
|
|
Well the users will all have their own unique ID so just match that to the correct areas of the sitemap and displau appropriatly on page.
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|