需要对动态生成的表行进行插入查询 [英] need an insert query for dynamically generated table rows
本文介绍了需要对动态生成的表行进行插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要对我的代码进行插入查询,我编写了代码以动态添加具有文本框的表行,例如,您只通过了HSSC考试,那么您必须填写2个教育水平的SSC,HSSC……或说您已通过Phd认证,然后通过SSC,HSSC,BS,MS,Phd认证,您必须填写所有内容,下面提供了我编写的代码,但是插入语句的外观如何,我不知道了
使用ASP.NET 3.5(C#),SQL Server 2008
请检查:
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
Please check:
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);
}
}
<pre lang="HTML">
<%@ 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>
推荐答案
在同一个for循环中,您可以将两个字符串变量ine用于列名,将其他字符串变量用于值,
您可以通过sql客户端执行该字符串.
In a same for loop, u can take two string variables ine for column names and other for values,
u can execute that string through sql client..
这篇关于需要对动态生成的表行进行插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文