need an insert query for my code , i wrote code to add table rows having textboxes, dynamically, e.g yoh have only passed HSSC exam then you have to fill 2 levels of education SSC, HSSC......or say you have passed Phd , then SSC,HSSC,BS, MS, Phd, you have to fill all, for which i worte code , given below but how an insert statement would look like for it ,i have no idea anymore
Using 3.5(c#),sql server 2008

.cs code:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class trying : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        int cnt = Convert.ToInt32(DropDownList1.SelectedValue);
        GenerateTable(5, cnt);
    //Here’s the code block for the generating the Tables with TextBoxes.

    private void GenerateTable(int colsCount, int rowsCount)
        //Creat the Table and Add it to the Page
        Table table = new Table();
        table.ID = "Table1";

        // Now iterate through the table and add your controls 
        for (int i = 0; i < rowsCount; i++)
            TableRow row = new TableRow();
            for (int j = 0; j < colsCount; j++)
                TableCell cell = new TableCell();
                TableCell lblcell = new TableCell();
                TextBox tb = new TextBox();
                Label lbl = new Label();

                // Set a unique ID for each TextBox added
                tb.ID = "TextBoxRow_" + i + "Col_" + j;
                lbl.ID = "Label_" + i + "Col_" + j;
                lbl.Text = DropDownList1.Items[i].ToString();
                // Add the control to the TableCell

                // Add the TableCell to the TableRow

            // Add the TableRow to the Table

.aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="trying.aspx.cs" Inherits="trying" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <div id="pnlTextBox">
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="150px">
                <asp:ListItem Value="1">SSLC</asp:ListItem>
                <asp:ListItem Value="2">HSC</asp:ListItem>
                <asp:ListItem Value="3">Graduate</asp:ListItem>
                <asp:ListItem Value="4">Post Graduate</asp:ListItem>
                <asp:ListItem Value="5">Ph.D</asp:ListItem>
            <asp:Panel ID="Panel1" runat="server">


Re: need an insert query for dynamically generated table rows 80 80
Member Avatar

need an insert query for dynamically generated table rows

You can read this (it has an example which is simaliar to your):

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.