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 asp.net 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";
Page.Form.Controls.Add(table);
// 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
lblcell.Controls.Add(lbl);
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(lblcell);
row.Cells.Add(cell);
}
// Add the TableRow to the Table
table.Rows.Add(row);
}
Panel1.Controls.Add(table);
}
}
.aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="trying.aspx.cs" Inherits="trying" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<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:DropDownList>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>