asp.net, c#, dynamic users controls

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testing.aspx.cs" Inherits="Testing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="obout" Namespace="Obout.ComboBox" Assembly="obout_ComboBox" %>
<%@ Register assembly="obout_Interface" namespace="Obout.Interface" tagprefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>How many city do you want to be listed:
        <asp:DropDownList ID="Ddl_City" runat="server">
            <asp:ListItem Value="1" Text="1"></asp:ListItem>
            <asp:ListItem Value="2" Text="2"></asp:ListItem>
            <asp:ListItem Value="3" Text="3"></asp:ListItem>
          </asp:DropDownList>
    
     <table>
    <tr><td><div id="DivItemCode" runat="server"></div></td></tr>
    </table>
    </div>
    <br />
    <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
    <asp:Button ID="BtnSubmit" runat="server" Text="Submits" onclick="BtnSubmit_Click" />
    </form>
</body>
</html>

Open in new window

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void TotalCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        int TotalCountCity = int.Parse(Ddl_City.SelectedValue);
        for (int i = 0; i < TotalCountCity; i++)
        {
            // list textboxes like <asp:TextBox  name="txtCity_" & i & "><br>"

        }

         
    }
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        //if it is clicked, capture the value back and save into the database.
    }
}

Open in new window


On the code back, I just try to catch the value and save into the database.
how can i do that?

500 points for working codes.
Webboy2008Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

karl-henrikCommented:
What database are you using?

For example (with SqLite)

Grap the ADO adapter for SQlite from http://sourceforge.net/projects/sqlite-dotnet2/

Then you can use this code to select, insert, update delete or what ever you like :)

public static DataTable GetDataTable (string sql)
 
   {
 
    DataTable dt = new DataTable();
 
    try
 
    {
 
    SQLiteConnection cnn = new SQLiteConnection("Data Source=C:CheckoutWorldDominator.s3db");
 
    cnn.Open();
 
    SQLiteCommand mycommand = new SQLiteCommand(cnn);
 
    mycommand.CommandText = sql;
 
    SQLiteDataReader reader = mycommand.ExecuteReader();
 
    dt.Load(reader);
 
    reader.Close();
 
    cnn.Close();
 
    } catch {
 
    // Catching exceptions is for communists
 
    }
 
    return dt;
 

}

public static int ExecuteNonQuery(string sql)
 
{
 
    SQLiteConnection cnn = new SQLiteConnection("Data Source=C:CheckoutWorldDominator.s3db");
 
    cnn.Open();
 
    SQLiteCommand mycommand = new SQLiteCommand(cnn);
 
    mycommand.CommandText = sql;
 
    int rowsUpdated = mycommand.ExecuteNonQuery();
 
    cnn.Close();
 
    return rowsUpdated;
 
}
 
public static string ExecuteScalar(string sql)
 
{
 
    SQLiteConnection cnn = new SQLiteConnection("Data Source=C:CheckoutWorldDominator.s3db");
 
    cnn.Open();
 
    SQLiteCommand mycommand = new SQLiteCommand(cnn);
 
    mycommand.CommandText = sql;
 
    object value = mycommand.ExecuteScalar();
 
    cnn.Close();
 
if (value != null)
 
    {
 
        return value.ToString();
 
    }
 
    return "";
 
}

Hope it helps.
//Karl.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.