Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Design Question 1

Status
Not open for further replies.

JoeZim

MIS
Sep 11, 2003
87
US
Currently, we have an excel template that gathers input on customer credit lines and various pieces of collateral they pledge towards these credit lines. The template then displays this information in a grid/matrix type display, in the following manner:

Code:
--------------------------------------------

Production 	fac1    fac2    fac3    fac4

--------------------------------------------

Collat 1        ckbx	ckbx	ckbx	ckbx
Collat 2        ckbx	ckbx	ckbx	ckbx
Collat 3        ckbx	ckbx	ckbx	ckbx
Collat 4        ckbx	ckbx	ckbx	ckbx

What I would like to do is create some kind of grid/matrix to display the row headers and column headers from the input data. The user would have the ability to then put an "x" at the intersection of a given piece of collateral and credit loan (which indicates which pieces of collateral are associated with a given credit loan(s)). From there, I will need to perform numerous calculations based on the intersection of the two (row, column - indicated by the "x").

This was a natural fit for Excel, but there are limitations because the file gets too large. We are contemplating moving this to ASP.NET and I was looking for any advice or suggestions on how this may be setup.

Thanks in advance!

Joe
 
You could do this fairly easily in ASP.NET. Simply use a GridView (or DataGrid if you are not using version 2.0 of the framework) and place checkboxes in each cell. Once the user has made their selections, you can just loop through the GridView and see what selections they made.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the reply ca8msm. I was thinking about trying this using a DataGrid, but I was struggling on how to implement the Column Headers and the Row Headers.

In my sample layout in the original post, the fac1-fac4 and collat 1 - collat 4 are the user-input items that need to be assigned to each other, using the ckbx. I think if I can figure out how to get these to appear as row/column headers, that would get me well on my way.

Is this possible with a DataGrid?
 
Hello, I was just hoping someone could comment on how to get row and column headers setup in a datagrid, which will appear like my example in the original post?

Thanks!
 
Here's a simple example of what I meant (you'll just have to add the checkboxes to the grid):
Code:
        ' Declarations
        Dim arrRows As New ArrayList()
        Dim arrColumns As New ArrayList()
        Dim dt As New DataTable
        Dim dr As DataRow

        ' Add some columns
        arrColumns.Add(" ")
        arrColumns.Add("fac1")
        arrColumns.Add("fac2")
        arrColumns.Add("fac3")
        arrColumns.Add("fac4")

        ' Add some rows
        arrRows.Add("Collat1")
        arrRows.Add("Collat2")
        arrRows.Add("Collat3")
        arrRows.Add("Collat4")

        ' create a datatable of the above data
        Dim enumCols As IEnumerator = arrColumns.GetEnumerator
        While enumCols.MoveNext
            dt.Columns.Add(enumCols.Current)
        End While
        Dim enumRows As IEnumerator = arrRows.GetEnumerator
        While enumRows.MoveNext
            dr = dt.NewRow
            dr(0) = enumRows.Current
            dt.Rows.Add(dr)
        End While

        ' Bind the results to a grid
        GridView1.DataSource = dt
        GridView1.DataBind()


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks again ca8msm, this certainly gets me on my way. I will work with this template and see what I can do!
 
I've managed to get the grid working, with check boxes populating all the cells. Now, I'm trying to evaluate each checkbox to see if it has been checked. My code is:

This creates the Grid and adds the checkboxes

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        BindGrid()

        Dim di As DataGridItem
        Dim i As Integer
        Dim j As Integer

        j = 1

        For i = 0 To DataGrid1.Items.Count - 1

            di = DataGrid1.Items(i)

            Dim ci As Integer

            For ci = 4 To di.Cells.Count - 1
                Dim cb As New CheckBox
                Dim cell As TableCell = di.Cells(ci)
                cb.AutoPostBack = False
                cb.ID = "cb" & j
                cb.Text = "cb" & j
                cell.HorizontalAlign = HorizontalAlign.Right
                cell.Controls.Add(cb)

                j = j + 1

            Next

        Next

    End Sub

This routine is just trying to evaluate the very first checkbox to see if it has been checked or not. I'm trying to get this working before I move on to evaluating the entire Grid.

Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim Chk As CheckBox

        Dim j As Integer
        j = 1

        Chk = CType(DataGrid1.Items(0).FindControl("cb" & j), CheckBox)
        If Chk.Checked Then
            Label1.Text = "Yes"
        Else
        End If

    End Sub

Problem is that I get the following error on Button2_click:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 135: 'Chk = CType(DataGrid1.FindControl("cb1"), CheckBox)
Line 136: Chk = CType(DataGrid1.Items(0).FindControl("cb" & j), CheckBox)
Line 137: If Chk.Checked Then
Line 138: 'Get ID
Line 139: Label1.Text = "Yes"

Source File: c:\inetpub\ Line: 137

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
testing.WebForm1.Button2_Click(Object sender, EventArgs e) in c:\inetpub\ System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


Any ideas on what I'm doing wrong?
 
It appears that your checkboxes aren't part of the page's controls when you click button 2.

To avoid this issue, add your checkboxes in the <ItemTemplate> in each of your DataGrid columns. You can loop through them later on the get their values in the button2_submit.
 
The problem is there will be a different number of columns each user session. The columns are built based on input from previous pages. I need to dynamically add the check boxes to fill the grid each time.

Once the user selects their checkboxes, I will need to evaluate them, linking each row header (cells 0, 1, 2, 3) with it's associated column header, based on the checked box.

 
You can dynamically add columns and checkboxes and set column headings in you "OnDataBound event which would be the optimal place to do this.
 
I just tried the following, which seems to work:

I put my BindGrid() in the Page_Init:

Code:
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
        BindGrid()

    End Sub

Then, I put the evaluation of the first checkbox on a button:

Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim Chk As CheckBox
        Dim i As Integer

        i = 1

        Chk = CType(DataGrid1.Items(0).FindControl("cb" & i), CheckBox)

        If Chk.Checked = True Then

            Label1.Text = "Yes"
        Else
            Label1.Text = "No"
        End If

    End Sub

This seems to get me back on track, but I'll see if I run into problems as I plow forward.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top