In general the program I am trying to create is for horse racing.
Okay so I am trying to figure out how to add multiple names to a list from a textbox on button click. I want to be able to use the same textbox and button to continue to add to the list without having to close the window and reopen it. I will need to be able to access the list later for the user to input times and scores for each rider in the list. I'm not so much looking for exactly how to do this but a push in the right direction would be nice. I'm kind of new to programing but I have a pretty firm grasp on C# basics and I want to learn more. Hope someone is able to help me out here a little bit. :)
Loading
Khan Abrar AhmedPosted Jun 4, 2014, 3:27 AM
[Serializable]
public class Names
{
public string Name { get; set; }
}
protected void btnClick_OnClik(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtName.Text))
{
List
if (ViewState["lstValue"] != null)
{
lstName = (List
}
Names objName = new Names();
objName.Name = txtName.Text;
//
lstName.Add(objName);
ViewState["lstValue"] = lstName;
RepName.DataSource = lstName;
RepName.DataBind();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\Brain\Name.txt"))
{
foreach (Names line in lstName)
{
// If the line doesn't contain the word 'Second', write the line to the file.
file.WriteLine(line.Name);
}
}
}
}
BrianPosted Jun 4, 2014, 3:11 AM
I will try to rephrase what I'm trying to do I don't think it came across right.
Ultimately I want to have register rider form that I can input rider info such as Name, age group, and maybe a few other details. Then later after all the riders have been registered I want to be able to use that info to create a form that will take the names from each age group and create a form to enter rider times for the current event.
So you enter name and age (just to keep it short) click a submit button. Then all text fields should clear using txtbox.Clear(); so you can enter in the next name and so on.
I am thinking a list
I hope this make a bit more sense.
Khan Abrar AhmedPosted Jun 4, 2014, 2:43 AM
If I understand the problem so I can help you,
1. for data storage purpose what are you using.
2. if use sql server then every time if you click on button then save the data in database or create two button one is add and one save,
3. if you click on add button take the input from text box and add in the list.
like
List
Protect void btnAddClick(Object sender, eventargs e)
{
if(!string.isnullorempty(txtName.text)
{
string name = txtName.Text;
lstName.add(name);
}
}
4. And when you click on save then
Protect void BtnSaveClick(Object sender, eventargs e)
{
//Save thedata in database, file or excel
}