Frage

I have several text boxes on my web page. These are optional for users, however I want them to be in order all the time. So say I have 6 text boxes which are optional for the user, and the user enters data into text boxes 2, 3, 5 but leaves the others empty. When they submit the form I want to actually save that data into fields 1, 2, 3.

So basically I want to always push the data up the list, so that any empty fields are always the higher numbered text boxes.

I'm saving the string data in my database in 6 different fields, so value1, value2, value3 etc...

Is there a simple way to do this or not?
If not, then its ok as its more of an added feature than necessary.

War es hilfreich?

Lösung

Try this:

string Temp="";
if(txt1.Text!="")
    Temp=Temp+txt1.Text+"^";
if(txt2.Text!="")
    Temp=Temp+txt2.Text+"^";
if(txt3.Text!="")
    Temp=Temp+txt3.Text+"^";
if(txt4.Text!="")
    Temp=Temp+txt4.Text+"^";
if(txt5.Text!="")
    Temp=Temp+txt5.Text+"^";
if(txt6.Text!="")
    Temp=Temp+txt6.Text+"^";
Temp=Temp+"^^^^^^";
string Parts[] = Temp.Split('^');
txt1.Text=Parts[0];
txt2.Text=Parts[1];
txt3.Text=Parts[2];
txt4.Text=Parts[3];
txt5.Text=Parts[4];
txt6.Text=Parts[5];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top