I have one table into database named card_details which has two fields card_number, card_value. I want to create some asp.net application where user enter the value of card number in textbox and automatically fetch the respected card value into another textbox.
Suppose user has more than one card then we have to give one button (Add More Card). After clicking this button its automatically generate two textboxes on runtime as mentioned my requirement where user can put the card number and its finds the value in another textboxes. And its also sum the card values(Gross Total) and show into another textbox.
$('#idTextbox').val('type texh whatever you want');
idTextbox: id of the dynamic textbox.
Is this, what you want to know.
Add a Panel to your page and then in the code behind of your Button use this to add controls dynamically:
TextBox dynamicTxtBox = new TextBox();
dynamicTxtBox.Text = "(enter text)";
dynamicTxtBox.ID = "dTxtBox";
Button dynamicBtn = new Button();
dynamicBtn.Click += new System.EventHandler(dynamicBtn_Click);
Panel1.Controls.Add(dynamicTxtBox);
Panel1.Controls.Add(dynamicBtn);
private void dynamicBtn_Click(Object sender, System.EventArgs e)
{
//your code here
}
Similarly you can add another TextBox as your requirement is two boxes.
Related
Issue
I have a simple ui, where user enters a value click on the "ok" button, the SubmitDateHandler click handler should then insert a label to the form with the value from the textbox. Then when this is repeated again, Add another label underneath the existing label. how to dynamically add multiple labels in a new line?
my code, at the moment is able to add one label, but not the second one.
private void SubmitDatebtn_Click(object sender, EventArgs e)
{
Label dateLabel = new Label();
dateLabel.Text = this.Controls.Find("Datetxt", true)[0].Text + Environment.NewLine;
this.LatestScoresPanel.Controls.Add(dateLabel);
}
Make sure to use FlowLayOutPanel, you can specify either veritcal or horizontal layout with it. Add the label to that like:
this.flowLayOutPanel.Controls.Add(dataLabel);
Make sure to specify FlowDirection either in code or design time.
flowLayoutPanel.FlowDirection = FlowDirection.TopDown;
I have a winforms project for a handheld device where I have multiple forms, I have one form to set the default options for another form, for example there is a comboBox on the default form for Locations which is populated with xml. what I want to do is when the user selects a location from the drop down on the defaults form and hits save, I need the selected location to be set as the default(show first) on the main form.
//Main Form
private void Form1_Load(object sender, EventArgs e)
{
string filePath = "/My Documents/AHWLtTables.txt";
dataSet1.ReadXml(filePath);
comboBox2.DataSource = dataSet1.Tables[8];
comboBox2.ValueMember = "Loc";
comboBox2.DisplayMember = "Desc";
}
This populates the comboBox with the xml data and I know that I can use SelectedIndex to set a default from the list I am just missing how to save the index # from the selection in the default options form and set it to that # in the main form.
Or am I approaching this wrong, should I make the dataSet a public object across all forms and call on it that way somehow?
How do you access to the second form?, you can send the parameter to the other form using a property (its a varible of any type with the get and set method), you can declare a property in the second form:
public int indexCombo {get; set;}
and when you call the form use something like:
Form2 myForm2 as Form2();
myForm2.indexCombo = comboBox2.selectedIndex; //I won't remember exactly the method XD sorry
//As you see first make the instace of the form and second set the value of the property
myForm2.show();
Finally to show the selected index en the new form in the load of the form:
comboBoxForm2.selectedIndex = indexCombo;
You could add a tag to the xml file that would save the index of the combo boxes. Adding the tag to the file is simple. You can just go into the file and do so. You just need to make up for that in your c# code. A good article is this here
I wrote a programme in VB to calculate the efficency of a heat exchanger with the temperature and other variables as user imput in a windows form. In VB is very simple, you just type:
Tcin = Val(Form1.Tempcin.Text);
Thin = Val(Form1.Temphotin.Text);
and the values are stored in Tcin and Thin.
But I have to translate the whole code to C# and I'm facing a lot of problems just to get the values form the text boxes in the windows form (all numerical). I have to use them in several methods as well, not only in the main form. The same happens with RadioButtons and CheckBoxes.
How do I call the variables or the "check status" of the buttons and checkboxes in the namespace and the several methods?
Inside your Form1.cs class, you can call:
Checkbox:
bool checked = this.checkBox1.Checked;
Radiobutton:
bool checked = this.radioButton1.Checked;
Textbox:
string text = this.textBox1.Text; // For text
- or -
int number = this.Int32.Parse(textBox1.Text); // For numbers
// If the textbox contains letters, there will be an error thrown (an exception)
Update the control names accordingly. You may have named your textbox myTextBox instead of textBox1.
This topic has to do with controls in C#. A button, a textbox, a checkbox, a radiobutton, a progressbar, and even a form ... these are all controls. This should help you with terminology if you want to Google further.
I have a main GUI in where I add data, in 12 columns. Each data is on one row as it comes in. This data is pushed into an array which is accessible globally. The array is dynamic 2D, growing each time I enter a set of data.
I wish to have a button that, when pressed, displays all the currently available data held in the array. If I can edit it then it's a step further, but at the moment I just need to be able to view the contents of my array.
My code is long as there are many buttons, listboxes doing different things. If needed, I can mail my code.
public void button1_Click(object sender, EventArgs e) {
Form2.Fm2 = new Form2();
Form2.Fm2.listBox1_SelectedIndexChanged();
if (Form2.Fm2 == null) {
Form2.Fm2.Show();
}
else {
Form2.Fm2.Show();
Form2.Fm2.BringToFront();
}
}
In the above, I want to pass values of my 2D array into the Listbox on Form2. Is this the correct methodology or am I missing something?
You can change the constructor of your display form to take the array, and then populate is a ListView or another appropriate control with it.
Is there a way to make a label automatically update itself so that I don't have to use a button to send out the command. What I have setup is a subtotal textbox, discount textbox, tax label, shipping textbox, and total label. So, when people fill in the subtotal, discount, and shipping, I want the tax label to be calculated, but only if previously a certain state was selected in another part of the form. So then, with all those filled in, I want the total label to be filled in. All of these I know I can do with a button, but I was wondering if there is a way to automate it using C# in Visual Studio.
Thanks.
I use the TextChanged Event to update such values between pairs of textboxes. Here are some extracts of my code:
private void onLongitudeTextChanged(object sender, EventArgs e) {
updateDistanceAndBearing();
}
updateDistanceAndBearing does some error checking - this can be a good idea if the user can put invalid values in and then updates the Text property of the other TextBoxes
I have text boxes but update the label.Text property instead.
It gets more messy (at least I found it so) if you have numeric updowns to get values
You can call a method to update the label in the change events for the controls.
For more detail, please supply more detail.
this is off the top of my head but should get you pretty close...
private void taxChanged(object sender, EventArgs e)
{
updateTax();
}
private void updateTax()
{
// the rest of your logic, checking state, etc.
//
this.Tax.Text = aValueCalculatedInYourLogicAbove;
updateTotal()
}
private void updateTotal()
{
// sum up whatever fields need to be summed
//
this.Tax.Text = aTotalValueCalculatedAbove;
}