Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai all
i have strucked here
i have atextbox and one button so if i click one in textbox one panelcontrol with table should appear
so if i enter 2 in textbox two panelcontrols with tables in it should be displayed
up to here working fine when saving single table valuues to database they are inserting using storedprocesure up to here also fine when inserting two panelcontrols or threepanel with tables data to database here problem coming

they are saving like
for ex in database firstname is there they are inserting like ravi,ram,raj in firstname field
not like ram and raj have to be insert in next records they are saving in one record
below is my code plz helpme
C#
public partial class addnewprac : System.Web.UI.Page
{
    int count;
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        count = Convert.ToInt32(TextBox1.Text);
        for (int i = 0; i < count; i++)
        {
            // int index = Panel1.Controls.OfType<textbox>().ToList().Count + 1;
            
            Table tbldynamic = new Table();
            tbldynamic.ID = "tbl" + i.ToString();
            TableCell tc = new TableCell();
            TableCell tc1 = new TableCell();
            TableRow tr = new TableRow();
            Label lbl = new Label();
            
            lbl.ID = "lbluid";
            lbl.Text = "Studentfirstname:";
            tc.Controls.Add(lbl);
            
            TextBox userid = new TextBox();
            userid.ID = "txtuid"+i;
            tc1.Controls.Add(userid);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label lblName = new Label();
            lblName.ID = "lblName";
            lblName.Text = "Studentlastname:";
            tc.Controls.Add(lblName);
            TextBox txtName = new TextBox();
            txtName.ID = "txtNamea"+i;
            tc1.Controls.Add(txtName);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label goingsc = new Label();
            goingsc.ID = "lblEmaila";
            goingsc.Text = "Going to school:";
            tc.Controls.Add(goingsc);
            CheckBox chk = new CheckBox();
            chk.ID = "chkaa"+i;
            chk.Text = "yes";
            tc1.Controls.Add(chk);
            
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label lblEmailab = new Label();
            lblEmailab.ID = "lblEmail";
            lblEmailab.Text = "SCHOOLNAME:";
            tc.Controls.Add(lblEmailab);
            TextBox schoolname = new TextBox();
            schoolname.ID = "sname"+i;
            tc1.Controls.Add(schoolname);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label grade = new Label();
            grade.ID = "lblEmailabc";
            grade.Text = "grade:";
            tc.Controls.Add(grade);
            DropDownList dpd = new DropDownList();
            ListItem[] items = new ListItem[3];
            items[0] = new ListItem("A Grade", "1");
            items[1] = new ListItem("B Grade", "2");
            
            items[2] = new ListItem("C Grade", "3");
            dpd.Items.AddRange(items);
            dpd.DataBind();
            dpd.ID = "select"+i;
            
            tc1.Controls.Add(dpd);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
                        
            Panel1.Controls.Add(tbldynamic);
        }
    }

    protected void btnSubmit_click(object sender, EventArgs e)
    {
        TextBox firstname = (TextBox)Panel1.FindControl("txtuid");
        
        TextBox lastname = (TextBox)Panel1.FindControl("txtNamea");
        CheckBox chkk = (CheckBox)Panel1.FindControl("chkaa");
        TextBox txttt = (TextBox)Panel1.FindControl("sname");
        DropDownList dda = (DropDownList)Panel1.FindControl("select");
        Response.Write(firstname.Text);
        Response.Write(lastname.Text);
        Response.Write(chkk.Text);
        Response.Write(txttt.Text);
        Response.Write(dda.Text);
        SqlConnection con = new SqlConnection("Data Source=HOME;Initial Catalog=login;Integrated Security=True");
        
        SqlCommand cmd = new SqlCommand("[student info]", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        con.Open();
        cmd.Parameters.AddWithValue("@sname", firstname.Text);
        cmd.Parameters.AddWithValue("@slname", lastname.Text);
        cmd.Parameters.AddWithValue("@gsch", chkk.Text);
        cmd.Parameters.AddWithValue("@ssname", txttt.Text);
        cmd.Parameters.AddWithValue("@sgr", dda.SelectedItem.Text);
        cmd.ExecuteNonQuery();
        
        con.Close();    
    }

my stored procesure is
SQL
USE [login]
GO

/****** Object: StoredProcedure [dbo].[student info] Script Date: 11/03/2015 15:06:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE procedure [dbo].[student info]
(
    @sname nvarchar(50),
    @slname nvarchar(50),
    @gsch bit,
    @ssname nvarchar(50),
    @sgr nvarchar(50)
)
as
begin

    insert into studentdetails values(@sname,@slname,@gsch,@ssname,@sgr)
end
GO

any body helpme
thank and regards
raviram
Posted
Updated 2-Nov-15 23:46pm
v2
Comments
Sinisa Hajnal 3-Nov-15 6:48am    
Why are you calling response.write in submit? You have controls and their values...set a breakpoint and see what are the values you're sending to the database.
raviram123 3-Nov-15 12:19pm    
sir just for checking i have written response.write.ihave checked using breakpoint there also coming firstname values side by side like ram,raj

1 solution

Your question is very hard to figure but I am trying to guess your problem here.

You need to call the stored procedure inside a loop.
1. In the submit button click, find the number of tables
2. Loop through them.
3. Inside the loop, find controls and call the stored procedure.

See what happens and try to debug...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900