Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

asp.net, c#, dynamic users controls

Posted on 2011-10-05
1
Medium Priority
?
274 Views
Last Modified: 2012-05-12
<%@ 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.
0
Comment
Question by:Webboy2008
1 Comment
 
LVL 3

Accepted Solution

by:
karl-henrik earned 2000 total points
ID: 36923551
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question