How to save multiple Textbox and radiobutton's value in for loop

Posted by t5j9033387989 under ASP.NET on 12/20/2013 | Points: 10 | Views : 2045 | Status : [Member] | Replies : 6
I use linq to sql,i dynamicallu create textobes and radiobuttons as per value of database,
Here is the code for that,


var r = from a in db.EMR_EVENTs
where a.EventID == (int)Session["eventid"]


select new
{
No_Of_Extra_Invitee=a.Allowed_guest_per_invitee
};

var ev1 = r.First();
int? count = ev1.No_Of_Extra_Invitee;


int? rowCount = ev1.No_Of_Extra_Invitee;
Session["rc"] = rowCount;

for (int i = 0; i < rowCount; i++)
{

TextBox txtfirstname = new TextBox();
TextBox txtlastname = new TextBox();
TextBox txtemail = new TextBox();

RadioButton chkmale = new RadioButton();
RadioButton chkfemale = new RadioButton();


txtfirstname.ID = "txtfirstname" + i.ToString();
txtlastname.ID = "txtlastname" + i.ToString();
txtemail.ID = "txtemail" + i.ToString();
txtfirstname.CssClass = "form-control";
txtlastname.CssClass = "form-control";
txtemail.CssClass = "form-control";
txtemail.Text = "E-Mail Address";
txtfirstname.Text = "First Name";
txtlastname.Text = "Last Name";


chkmale.ID = "chkmale" + i.ToString();
chkfemale.ID = "chkfemale" + i.ToString();


chkmale.Text = "Male";
chkfemale.Text = "Female";

pnl.Controls.Add(txtfirstname);
pnl.Controls.Add(txtlastname);
pnl.Controls.Add(txtemail);
pnl.Controls.Add(chkmale);
pnl.Controls.Add(chkfemale);


}


if i got No_Of_Extra_Invitee=2 then i got 6 textbox and 4 radiobuttons

Now i want to saved this control's value(text),though i give it default text,but i want to save it's runtime value so in submit button i implement like this,



protected void Submit(object sender, EventArgs e)
{
int rccount = Convert.ToInt32(Session["rc"]);

ExtraInviteeBL eb = new ExtraInviteeBL();
for (int i = 0; i <rccount; i++)
{
//logic for add value of textbox's and radiobutton's in database

}



but now i don't know how insert value of this textbox and radiobuttns can anyone give me suggestion for that
Thanks in advance..!

mark this answer if it will really help you,

Thanks&Regards
ketan



Responses

Posted by: vishalneeraj-24503 on: 12/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Please write your insert statement inside submit button and loop through the row count ad make a semi-colon saperated insert query and insert in one shot.

str = "insert into tbl_name value(1,1);
insert into tbl_name value(2,2);"

insert in one shot by passing this str to command object.

please go through my artical,

http://www.dotnetfunda.com/articles/show/2734/insert-multiple-records-in-one-shot-to-avoid-database-hitting


t5j9033387989, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: t5j9033387989 on: 12/20/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for your valuable reply,

but i use linq to sql as i mention above so i can't use this method for insert data.
i have to use this type method for insert data into database
ExtraInviteeBL eb = new ExtraInviteeBL();
eb.txtfirstname1=txtfirstname.text

so as per that give me other solution,

mark this answer if it will really help you,

Thanks&Regards
ketan

t5j9033387989, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer:-
http://msdn.microsoft.com/en-us/library/bb763516%28v=vs.110%29.aspx
http://www.codeproject.com/Articles/46422/A-LINQ-Tutorial-Adding-Updating-Deleting-Data

t5j9033387989, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: t5j9033387989 on: 12/20/2013 [Member] Starter | Points: 25

Up
0
Down
Sorry but this isnot help me,can you give me other solution.
i also not find your link which you give me in first solution.

mark this answer if it will really help you,

Thanks&Regards
ketan

t5j9033387989, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Actually the link i gave in 1st solution is pending for approval. That's why you are not having access to that link.
I will provide you the solution.

t5j9033387989, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: t5j9033387989 on: 12/20/2013 [Member] Starter | Points: 25

Up
0
Down
yeh sure thanks,yar. actually i found that your answers are so helpful. for everyone.
Thanks for that.

m waiting for that.

mark this answer if it will really help you,

Thanks&Regards
ketan

t5j9033387989, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response