Problems with displaying dynamic Html Table control

Discussion in 'ASP .Net' started by Al Wilkerson, Mar 13, 2005.

  1. Al Wilkerson

    Al Wilkerson Guest

    Hey,

    I have a Web Form with a drop down list, textbox, and search button.
    When click the search button an SQL server database is queried fordata.
    Once I have the data in a dataset I use the dataset to dynamically create a
    Html Table control.

    I want to display the table on another frame page (target="main") without
    the web form controls (i.e. the textbox, search button, and dropdown list).
    I just want the table displayed only on the new seperate frame page.

    Problem 1 - The HTML Table does not display at all
    Problem 2 - The original web form controls are displayed on the new page

    When debug the correct data is retrieved from DB and the rows are populated.
    But the table does not display.

    In the following Code-Behind file example "maxrows" = 1 and "maxcolumns" = 8
    ------

    protected System.Web.UI.HtmlControls.HtmlTable t1;
    protected System.Web.UI.HtmlControls.HtmlSelect ddlSearch;
    protected System.Web.UI.HtmlControls.HtmlInputText txtSearch;
    protected System.Web.UI.HtmlControls.HtmlInputButton btnSearch;


    try
    {

    sDa = new OleDbDataAdapter(lSql,sConn);
    sDa.Fill(ds, "Products");


    }
    catch(Exception ex)
    {
    Response.Write("Problem filling DataSet " + ex.Message);
    }

    try
    {

    t1 = new HtmlTable();

    int maxrows = 0;
    int maxcolumns = 0;

    maxrows = ds.Tables["Products"].Rows.Count;
    maxcolumns = ds.Tables["Products"].Columns.Count;

    int row = 0;

    for( int i = 0; i < maxrows; i++)
    {

    HtmlTableRow r = new HtmlTableRow();
    row = row + 1;

    for( int j = 0; j < maxcolumns; j++)
    {
    HtmlTableCell c = new HtmlTableCell();

    c.Controls.Add(new
    LiteralControl(Convert.ToString(ds.Tables["Products"].Rows[j])));
    r.Cells.Add(c);
    }
    t1.Rows.Add(r);

    }

    t1.Visible = true;


    ASPX File
    ------------

    <body MS_POSITIONING="GridLayout">
    <TABLE id="t1" bgcolor="silver" border="5" align="right" runat="server">
    </TABLE>
    <form id="Search" method="post" target="main" runat="server">
    <SELECT id="ddlSearch" style="Z-INDEX: 101; LEFT: 35px; POSITION:
    absolute; TOP: 37px" runat="server">
    <OPTION value="Title" selected>Title</OPTION>
    <OPTION value="Type">Type</OPTION>
    <OPTION value="Author">Author</OPTION>
    <OPTION value="Edition">Edition</OPTION>
    <OPTION value="Copyright">Copyright</OPTION>
    </SELECT>
    <INPUT id="btnSearch" style="Z-INDEX: 102; LEFT: 318px; POSITION:
    absolute; TOP: 38px" type="button" value="Search" runat="server">
    <INPUT id="txtSearch" style="Z-INDEX: 103; LEFT: 130px; POSITION:
    absolute; TOP: 37px" type="text" runat="server">





    --
    Al
     
    Al Wilkerson, Mar 13, 2005
    #1
    1. Advertising

  2. What I would do is create a normal form in html with the target set to the
    frame and the action where you want to display the table. In this new page
    you would be able to populate the dataset doing the SQL using the fields
    passed in the Request.Form

    <form name="forma" action="table.aspx" target="framename">
    <input type="text" name="text1" value="">
    <select name="select1">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    </select>
    </form>

    in table.aspx

    you would build the SQL:

    Dim sSql as String = "SELECT * FROM TABLE WHERE FIELD1 ='" &
    Request.Form("text1") & "' AND FIELD2="& REquest.Form("select1")

    With the sql you populate the dataset and create the output.


    "Al Wilkerson" <> wrote in message
    news:...
    > Hey,
    >
    > I have a Web Form with a drop down list, textbox, and search button.
    > When click the search button an SQL server database is queried fordata.
    > Once I have the data in a dataset I use the dataset to dynamically create
    > a Html Table control.
    >
    > I want to display the table on another frame page (target="main") without
    > the web form controls (i.e. the textbox, search button, and dropdown
    > list). I just want the table displayed only on the new seperate frame
    > page.
    >
    > Problem 1 - The HTML Table does not display at all
    > Problem 2 - The original web form controls are displayed on the new page
    >
    > When debug the correct data is retrieved from DB and the rows are
    > populated. But the table does not display.
    >
    > In the following Code-Behind file example "maxrows" = 1 and "maxcolumns" =
    > 8
    > ------
    >
    > protected System.Web.UI.HtmlControls.HtmlTable t1;
    > protected System.Web.UI.HtmlControls.HtmlSelect ddlSearch;
    > protected System.Web.UI.HtmlControls.HtmlInputText txtSearch;
    > protected System.Web.UI.HtmlControls.HtmlInputButton btnSearch;
    >
    >
    > try
    > {
    >
    > sDa = new OleDbDataAdapter(lSql,sConn);
    > sDa.Fill(ds, "Products");
    >
    >
    > }
    > catch(Exception ex)
    > {
    > Response.Write("Problem filling DataSet " + ex.Message);
    > }
    >
    > try
    > {
    >
    > t1 = new HtmlTable();
    >
    > int maxrows = 0;
    > int maxcolumns = 0;
    >
    > maxrows = ds.Tables["Products"].Rows.Count;
    > maxcolumns = ds.Tables["Products"].Columns.Count;
    >
    > int row = 0;
    >
    > for( int i = 0; i < maxrows; i++)
    > {
    >
    > HtmlTableRow r = new HtmlTableRow();
    > row = row + 1;
    >
    > for( int j = 0; j < maxcolumns; j++)
    > {
    > HtmlTableCell c = new HtmlTableCell();
    >
    > c.Controls.Add(new
    > LiteralControl(Convert.ToString(ds.Tables["Products"].Rows[j])));
    > r.Cells.Add(c);
    > }
    > t1.Rows.Add(r);
    >
    > }
    >
    > t1.Visible = true;
    >
    >
    > ASPX File
    > ------------
    >
    > <body MS_POSITIONING="GridLayout">
    > <TABLE id="t1" bgcolor="silver" border="5" align="right" runat="server">
    > </TABLE>
    > <form id="Search" method="post" target="main" runat="server">
    > <SELECT id="ddlSearch" style="Z-INDEX: 101; LEFT: 35px; POSITION:
    > absolute; TOP: 37px" runat="server">
    > <OPTION value="Title" selected>Title</OPTION>
    > <OPTION value="Type">Type</OPTION>
    > <OPTION value="Author">Author</OPTION>
    > <OPTION value="Edition">Edition</OPTION>
    > <OPTION value="Copyright">Copyright</OPTION>
    > </SELECT>
    > <INPUT id="btnSearch" style="Z-INDEX: 102; LEFT: 318px; POSITION:
    > absolute; TOP: 38px" type="button" value="Search" runat="server">
    > <INPUT id="txtSearch" style="Z-INDEX: 103; LEFT: 130px; POSITION:
    > absolute; TOP: 37px" type="text" runat="server">
    >
    >
    >
    >
    >
    > --
    > Al
    >
     
    Joaquin Corchero, Mar 14, 2005
    #2
    1. Advertising

  3. Al Wilkerson

    Al Wilkerson Guest

    Hey,

    But I want the action (server code) to be done in the code-behind C#
    file. I wanted to avoid using the <script> tag in the aspx file.

    Otherwise, what you're saying I would build (using script tag) the
    database query and dataset population, in the aspx file which also holds
    a table, and then retreive the values from the aspx file (maybe passing
    session variables) to the C# code-behind file to display the table.

    It seems like your solution is the old HTML/ASP way, and not the .Net
    way. Am I correct in this?

    Thanks,

    Al

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Al Wilkerson, Mar 14, 2005
    #3
  4. Hi,

    From server side code, you cannot access a page on different frame. Hence,
    you cannot show the html table in a different page or frame.

    You can have two <div> tags, one with the search details and other you can
    use it for inserting the html table. You can set the visibility of first div
    off and display only the second div.

    In your code,
    > t1.Visible = true;


    after creating the html table, you need to add this to the page or a
    control. If you second div id is "resulttable", you can add,

    resulttable.Controls.Add(t1);

    This will insert the newly created html table in the div.


    Saravanan K V

    "Al Wilkerson" wrote:

    >
    >
    > Hey,
    >
    > But I want the action (server code) to be done in the code-behind C#
    > file. I wanted to avoid using the <script> tag in the aspx file.
    >
    > Otherwise, what you're saying I would build (using script tag) the
    > database query and dataset population, in the aspx file which also holds
    > a table, and then retreive the values from the aspx file (maybe passing
    > session variables) to the C# code-behind file to display the table.
    >
    > It seems like your solution is the old HTML/ASP way, and not the .Net
    > way. Am I correct in this?
    >
    > Thanks,
    >
    > Al
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
     
    =?Utf-8?B?U2FyYXZhbmFuIEsgVg==?=, Mar 15, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    389
    Ken Varn
    May 19, 2004
  2. Al Wilkerson
    Replies:
    1
    Views:
    2,769
    =?Utf-8?B?U2FyYXZhbmFuIEsgVg==?=
    Mar 14, 2005
  3. Geary
    Replies:
    2
    Views:
    740
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 12, 2007
  4. Sameer
    Replies:
    1
    Views:
    790
  5. ruds
    Replies:
    5
    Views:
    4,100
    Mark Space
    Mar 1, 2008
Loading...

Share This Page