Dynamic Table Build Using DataRowView

Discussion in 'ASP .Net Building Controls' started by hoosierprogrammer@yahoo.com, Sep 13, 2004.

  1. Guest

    All

    I'm trying to build a table dynamically from a DataView using
    IEnumerator. It will be read only data for printing on Avery 5160
    label stock.

    I had some trouble making the while(viewCounter.MoveNext()) and
    foreach(DataRowView in dv) samples work as I was not able to stricly
    break these loops on the 3rd column.

    If the DataView has 6 records total, I need 2 rows of 3 cells.

    The code below gives me the correct table format but the
    "viewCounter.MoveNext();" inside the for loop is not working. I get a
    table where each cell has the same data.

    Is there a tweek that would make it work or is it totally off?

    Thanks, TD



    protected void BuildGroupList()
    {

    DataView dv = new DataView(PhoneList().Tables[0]);

    IEnumerator viewCounter = dv.GetEnumerator();
    DataRowView drv;

    viewCounter.MoveNext(); //move to the first record
    drv = (DataRowView) viewCounter.Current;

    // Generate rows and cells.
    int numrows = 10;
    int numcells = 3;
    for (int j=0; j<numrows; j++)
    {
    TableRow r = new TableRow();
    for (int i=0; i<numcells; i++)
    {
    TableCell c = new TableCell();
    c.Text = i.ToString() + "<br>" + drv.Row["Info"].ToString();
    r.Cells.Add(c);
    viewCounter.MoveNext();
    }
    tblGroupList.Rows.Add(r);
    }





    }
    , Sep 13, 2004
    #1
    1. Advertising

  2. Guest

    Here is the solution for my question in case anyone needs a way to do
    this.

    This code populates a dataset from oracle using a ref cursor. The
    table control exists on the page with no rows until this fills it. It
    creates rows and then fills them with no more than 3 cells.

    Each cell is filled with a chunk of demographic data that the cursor
    returns named "Info".

    I hope it helps.

    TD



    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Text;
    using System.Data.OracleClient;
    using System.Collections.Specialized;

    namespace DoctorPages
    {
    /// <summary>
    /// Summary description for DisplayDetail.
    /// </summary>
    public class DisplayDetail : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label lblGroupList;
    protected System.Web.UI.WebControls.Table tblGroupList;

    protected string iDetailType;
    protected string iDetailInfo;
    protected string oMsg;
    protected string oInfo;
    protected DataRowView drv;
    protected IEnumerator viewCounter;

    protected string lInfo;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here

    BuildGroupList();

    }


    #region DataSet PhoneList()
    protected DataSet PhoneList()
    {
    iDetailType = "test";
    iDetailInfo = Request.QueryString["Group"];

    System.Data.OracleClient.OracleConnection conn = new
    OracleConnection("Data Source=data_source_name;User
    ID=UID;Password=PWD;Max Pool Size=20");
    OracleCommand cmd = conn.CreateCommand();
    cmd.CommandText = "SCHEMA.PACKAGE.PROCEDURE";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("iDetailType", OracleType.VarChar,50).Value =
    iDetailType;
    cmd.Parameters.Add("iDetailInfo", OracleType.VarChar,50).Value =
    iDetailInfo;
    cmd.Parameters.Add("oInfo", OracleType.VarChar,250).Direction =
    ParameterDirection.Output;
    cmd.Parameters.Add("oMsg", OracleType.VarChar,250).Direction =
    ParameterDirection.Output;
    cmd.Parameters.Add("oDetailInfoCurs", OracleType.Cursor).Direction =
    ParameterDirection.Output;


    DataSet ds = new DataSet();

    OracleDataAdapter adapter = new OracleDataAdapter(cmd);

    try
    {
    conn.Open();
    adapter.Fill(ds);
    oMsg = cmd.Parameters["oMsg"].Value.ToString();
    oInfo = cmd.Parameters["oInfo"].Value.ToString();
    lInfo = oInfo;
    }
    catch(Exception ex)
    {
    Response.Write(ex.ToString());
    }
    finally
    {
    cmd.Parameters.Clear();
    cmd.Dispose();
    conn.Close();
    }

    return ds;



    }// close PhoneList()
    #endregion


    #region BuildGroupList()
    protected void BuildGroupList()
    {

    DataView dv = new DataView(PhoneList().Tables[0]);
    int recNum; //total individual records returned in the cursor
    int colNum = 1; // used if records returned is less than 3
    int rowNum = 1;
    int maxColNum = 3; // 3 rows per column max

    if(dv.Count > 0) //assign values
    {
    //get record count
    recNum = dv.Count;
    Response.Write("recNum - " + recNum + "<br>");

    //set column count
    if(recNum > maxColNum)
    {
    //more likely scenario
    colNum = maxColNum;
    }
    else
    {
    colNum = recNum;
    }
    Response.Write("colNum - " + colNum + "<br>");

    //set number of actual rows

    rowNum = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(recNum)/Convert.ToDouble(colNum)));
    // Math.Ceiling returns double

    Response.Write("Math - " + recNum + "/" + colNum + "=" + rowNum +
    "<br>");

    Response.Write("rowNum - " + rowNum + "<br>");
    //Response.Write("rowNum1 - " + rowNum1 + "<br>");

    }
    else
    {

    Response.Write("dv.count < 0 . dv.Count is: " + dv.Count);

    } // end assign values


    // begin table build
    viewCounter = dv.GetEnumerator();
    viewCounter.MoveNext();
    bool eof = false;

    for (int i=0; i<rowNum; i++)
    {
    TableRow tempRow = new TableRow();
    tempRow.CssClass = "trGroupList";

    for (int j=0; j<colNum && !eof; j++)
    {
    drv = (DataRowView) viewCounter.Current;
    TableCell tempCell = new TableCell();
    tempCell.CssClass = "tdGroupList";
    tempCell.Text += drv.Row[0].ToString();
    tempRow.Cells.Add(tempCell);
    eof = !viewCounter.MoveNext();

    }

    tblGroupList.Rows.Add(tempRow);
    }


    }
    #endregion BuildGroupList()



    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion







    }
    }

















    wrote in message news:<>...
    > All
    >
    > I'm trying to build a table dynamically from a DataView using
    > IEnumerator. It will be read only data for printing on Avery 5160
    > label stock.
    >
    > I had some trouble making the while(viewCounter.MoveNext()) and
    > foreach(DataRowView in dv) samples work as I was not able to stricly
    > break these loops on the 3rd column.
    >
    > If the DataView has 6 records total, I need 2 rows of 3 cells.
    >
    > The code below gives me the correct table format but the
    > "viewCounter.MoveNext();" inside the for loop is not working. I get a
    > table where each cell has the same data.
    >
    > Is there a tweek that would make it work or is it totally off?
    >
    > Thanks, TD
    >
    >
    >
    > protected void BuildGroupList()
    > {
    >
    > DataView dv = new DataView(PhoneList().Tables[0]);
    >
    > IEnumerator viewCounter = dv.GetEnumerator();
    > DataRowView drv;
    >
    > viewCounter.MoveNext(); //move to the first record
    > drv = (DataRowView) viewCounter.Current;
    >
    > // Generate rows and cells.
    > int numrows = 10;
    > int numcells = 3;
    > for (int j=0; j<numrows; j++)
    > {
    > TableRow r = new TableRow();
    > for (int i=0; i<numcells; i++)
    > {
    > TableCell c = new TableCell();
    > c.Text = i.ToString() + "<br>" + drv.Row["Info"].ToString();
    > r.Cells.Add(c);
    > viewCounter.MoveNext();
    > }
    > tblGroupList.Rows.Add(r);
    > }
    >
    >
    >
    >
    >
    > }
    , Sep 15, 2004
    #2
    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. Dinky

    DataRowView

    Dinky, Jul 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,866
    Benjie Fallar
    Jul 10, 2003
  2. karim
    Replies:
    5
    Views:
    2,936
    David Waz...
    Jul 11, 2003
  3. =?Utf-8?B?ZXRyb3BpYw==?=

    'System.Data.DataRowView' does not contain a property ......

    =?Utf-8?B?ZXRyb3BpYw==?=, May 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,646
    =?Utf-8?B?ZXRyb3BpYw==?=
    May 10, 2004
  4. MS
    Replies:
    0
    Views:
    3,214
  5. rote
    Replies:
    4
    Views:
    733
    Eliyahu Goldin
    Feb 29, 2008
Loading...

Share This Page