Click here to Skip to main content
15,892,737 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Performance Tuning Pin
Brij3-Oct-08 1:08
mentorBrij3-Oct-08 1:08 
QuestionHelp With Dynamic TextBox Pin
DotNetCoderJunior2-Oct-08 21:04
DotNetCoderJunior2-Oct-08 21:04 
AnswerRe: Help With Dynamic TextBox Pin
acroitoriu2-Oct-08 21:33
acroitoriu2-Oct-08 21:33 
GeneralRe: Help With Dynamic TextBox Pin
DotNetCoderJunior2-Oct-08 22:01
DotNetCoderJunior2-Oct-08 22:01 
GeneralRe: Help With Dynamic TextBox Pin
acroitoriu2-Oct-08 22:09
acroitoriu2-Oct-08 22:09 
GeneralRe: Help With Dynamic TextBox Pin
DotNetCoderJunior2-Oct-08 22:22
DotNetCoderJunior2-Oct-08 22:22 
GeneralRe: Help With Dynamic TextBox Pin
acroitoriu2-Oct-08 22:29
acroitoriu2-Oct-08 22:29 
GeneralRe: Help With Dynamic TextBox Pin
DotNetCoderJunior2-Oct-08 22:39
DotNetCoderJunior2-Oct-08 22:39 
Dude i'm also confusedConfused | :confused:

heres my code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections;

public partial class NewServerConfig : System.Web.UI.Page
{

    DataRow odr;
    Table tblServer = new Table();

    string FieldName = "";
    TableRow tr = new TableRow();
    TableCell tcFields = new TableCell();
    TableCell tcFieldData = new TableCell();

    string server;
    protected void Page_Load(object sender, EventArgs e)
    {


        if (Session["LogedInID"] != null)
        {

            server = Request["id"].ToString();
            tblServer.ID = "tblid";
            int tblRows = Rows;
            int tblCols = Columns;
            tblServer = new Table();
            PlaceHolder1.Controls.Add(tblServer);

            if (!Page.IsPostBack)
            {
                CreateDynamicControls(server);

            }
            //CreateDynamicControls(server);
        }
        else
        {
            Response.Redirect("login.aspx");
        }

    }

    protected int Rows
    {
        get
        {
            return ViewState["Rows"] != null ? (int)ViewState["Rows"] : 0;
        }
        set
        {
            ViewState["Rows"] = value;
        }
    }

    // Columns property to hold the Columns in the ViewState
    protected int Columns
    {
        get
        {
            return ViewState["Columns"] != null ? (int)ViewState["Columns"] : 0;
        }
        set
        {
            ViewState["Columns"] = value;
        }
    }

    private void CreateDynamicControls(string serverID)
    {

        int tblRows = Rows;
        int tblCols = Columns;
        tblServer = new Table();
        tblServer.ID = "tblid";
        int i = 0;
        DataTable tblFields = GetData(server);


        foreach (DataRow rowField in tblFields.Rows)
        {
            tr = new TableRow();
            tcFields = new TableCell();
            Label lblFields = new Label();
            lblFields.Width = 60;
            lblFields.Text = rowField["fieldName"].ToString();
            tcFields.Controls.Add(lblFields);
            tr.Cells.Add(tcFields);
            DataTable tblFieldData = GetFieldData(serverID);
            foreach (DataRow row in tblFieldData.Rows)
            {


                string txtName = "txtbox" + (i + 1);
                tcFieldData = new TableCell();
                TextBox txtData = new TextBox();
                txtData.ID = txtName;
                tcFieldData.Controls.Add(txtData);
                tr.Cells.Add(tcFieldData);
                i++;


            }

            tblServer.Rows.Add(tr);


        }
        tblServer.ID = "tableID";
        PlaceHolder1.Controls.Add(tblServer);
        ViewState["dynamictable"] = true;

    }
    DataTable GetData(string strid)
    {
        string sql = "SELECT tFields.fieldName, tFields.id FROM tFields INNER JOIN tRelServerFields ON tFields.id = tRelServerFields.tFieldsFKid WHERE (tRelServerFields.tServerFKid = @serverID)";
        SqlConnection oCon = new SqlConnection(DatabaseConnection.ConnectionString);
        SqlCommand cmd = new SqlCommand(sql, oCon);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@serverID ", Convert.ToInt32(strid));
        DataTable tblData = new DataTable();
        new SqlDataAdapter(cmd).Fill(tblData);
        //tblData.DefaultView.
        return tblData;
    }
    DataTable GetFieldData(string strFieldID, string serverID)
    {
        string sql = "Select fieldData,id from tRelServerFields where tServerFKid = @serverID and  tFieldsFKid= @fieldsID ";
        SqlConnection oCon = new SqlConnection(DatabaseConnection.ConnectionString);
        SqlCommand cmd = new SqlCommand(sql, oCon);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@serverID ", serverID);
        cmd.Parameters.AddWithValue("@fieldsID  ", strFieldID);
        DataTable tblData = new DataTable();
        new SqlDataAdapter(cmd).Fill(tblData);
        //tblData.DefaultView.
        return tblData;
    }

    DataTable GetFieldData(string strid)
    {
        string sql = "Select id from tServer where id = @serverID ";
        SqlConnection oCon = new SqlConnection(DatabaseConnection.ConnectionString);
        SqlCommand cmd = new SqlCommand(sql, oCon);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@serverID ", Convert.ToInt32(strid));
        DataTable tblData = new DataTable();
        new SqlDataAdapter(cmd).Fill(tblData);
        //tblData.DefaultView.
        return tblData;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Hashtable ht;
        odr = (DataRow)Session["ClientLogon"];



        ht = new Hashtable();
        ht.Add("fieldName", txtNewField.Text);
        DataAccessLayer.PopulateData("tFields", ht);
    }



    protected void Button2_Click(object sender, EventArgs e)
    {
        SaveFieldname();
        CreateDynamicControls(server);

    }
    DataTable GetFieldid(string strName)
    {
        string sql = "select id from tFields where fieldName = @fieldName ";
        SqlConnection oCon = new SqlConnection(DatabaseConnection.ConnectionString);
        SqlCommand cmd = new SqlCommand(sql, oCon);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@fieldName ", strName);
        DataTable tblData = new DataTable();
        new SqlDataAdapter(cmd).Fill(tblData);
        //tblData.DefaultView.
        return tblData;
    }
    public void saveServerField(string strid)
    {
        Hashtable ht;
        odr = (DataRow)Session["ClientLogon"];
        ht = new Hashtable();
        ht.Add("tServerFKid", Convert.ToInt32(Request["id"]));
        ht.Add("tFieldsFKid", Convert.ToInt32(strid));

        DataAccessLayer.PopulateData("tRelServerFields", ht);



    }
    public void SaveFieldname()
    {
        Hashtable ht;
        ht = new Hashtable();
        ht.Add("fieldName", txtNewField.Text);
        DataAccessLayer.PopulateData("tFields", ht);
        FieldName = txtNewField.Text;

        DataTable dt = GetFieldid(FieldName);
        string newFieldid = "";
        foreach (DataRow dr in dt.Rows)
        {
            newFieldid = dr["id"].ToString();
        }


        saveServerField(newFieldid);




    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= tblServer.Rows.Count; i++)
        {

            Table tblServer1 = (Table)PlaceHolder1.FindControl("tblid");
            TextBox txtCtrl = (TextBox)tblServer1.FindControl("txtbox" + (i + 1));
            if (txtCtrl != null)
            {
                Button2.Text = txtCtrl.Text;
            }
        }


    }
}

GeneralRe: Help With Dynamic TextBox Pin
acroitoriu2-Oct-08 23:15
acroitoriu2-Oct-08 23:15 
GeneralRe: Help With Dynamic TextBox Pin
DotNetCoderJunior3-Oct-08 0:01
DotNetCoderJunior3-Oct-08 0:01 
AnswerRe: Help With Dynamic TextBox Pin
DotNetCoderJunior3-Oct-08 3:07
DotNetCoderJunior3-Oct-08 3:07 
QuestionReporting Service in Asp.net 2005 Pin
Member 31782792-Oct-08 21:02
Member 31782792-Oct-08 21:02 
AnswerRe: Reporting Service in Asp.net 2005 Pin
Sathesh Sakthivel3-Oct-08 3:03
Sathesh Sakthivel3-Oct-08 3:03 
QuestionDate Time picker [modified] Pin
member272-Oct-08 20:52
member272-Oct-08 20:52 
AnswerRe: Date Time picker Pin
acroitoriu2-Oct-08 21:29
acroitoriu2-Oct-08 21:29 
GeneralRe: Date Time picker Pin
Krazy Programmer2-Oct-08 21:40
Krazy Programmer2-Oct-08 21:40 
QuestionResponse.AddHeader() Pin
jhyn2-Oct-08 19:21
jhyn2-Oct-08 19:21 
AnswerRe: Response.AddHeader() Pin
acroitoriu2-Oct-08 21:19
acroitoriu2-Oct-08 21:19 
AnswerRe: Response.AddHeader() [modified] Pin
jhyn2-Oct-08 21:20
jhyn2-Oct-08 21:20 
QuestionExport image to excel Pin
saravanan052-Oct-08 19:09
saravanan052-Oct-08 19:09 
Questionhave a problem with sessions Pin
kheer2-Oct-08 18:33
kheer2-Oct-08 18:33 
AnswerRe: have a problem with sessions Pin
Sneha Bisht2-Oct-08 18:48
Sneha Bisht2-Oct-08 18:48 
GeneralRe: have a problem with sessions Pin
kheer2-Oct-08 18:57
kheer2-Oct-08 18:57 
GeneralRe: have a problem with sessions Pin
N a v a n e e t h2-Oct-08 22:29
N a v a n e e t h2-Oct-08 22:29 
AnswerRe: have a problem with sessions Pin
Brij2-Oct-08 19:02
mentorBrij2-Oct-08 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.