Urgent: How to populate selected records in a popup window

Greeting,
I use Repeater to display data on the asp.net form. It contains a checkbox field which is used to determine which row need to be updated. Once the form being submitted, I want to have a popup window which use repeater to show all the selected records from the previous(main) form. The main form will be redirected to another page and popup window need to be on top of the screen.

Thanks in advance.
mrongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThaloxCommented:

I would do the following:

first store the original dataset/datarows in the session
then on submit go through the repeater items and check whether the checkbox is checked or not and store these rows in another session-variable.

protected void submit_click(object sender, EventArgs e) {
DataSet ds = (DataSet)Session["rowdata"];
ArrayList rows = new ArrayList();

for(int i = 0; i < repeater.Items.Length; i++) {

  CheckBox chb = (CheckBox)repeater.Items[i].findControl("chb");
  if ((chb != null) && (chb.Checked)) {
    rows.Add(ds.Tables[0].Rows[i]);
  }
}
Session["updateRows"] = rows;
}

to popup a window use the onload event in the body-tag of your page

<body onload="window.open('updateRows.aspx')">

where updateRows.aspx is the popup-page. in Page_load of this page get the rows from the session and bind them to the repeater

protected void Page_Load() {
  if (!IsPostBack) {

     uptRepeater.DataSource = Session["updateRows"];
     uptRepeater.DataBind();
  }
}

I hope that helps,

Thalox
0
mrongAuthor Commented:
Thalox,
Is your code in VB.net? I tried your code in my onClick function ..it returned me lots of error. Below is what I have for onClick function.

Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
'code goes here
End Sub

Thanks.
0
ThaloxCommented:

no sorry in c#
I do not use vb very often, so this will probably not be correct (I think casts are handled different in vb), but it should be easy to correct the rest

Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
DataSet ds = (DataSet)Session["rowdata"]
rows as ArrayList = new ArrayList()
dim i as integer

for  i = 0 to repeater.Items.Length - 1

  dim chb as CheckBox = (CheckBox)repeater.Items[i].findControl("chb")
  if (chb != null) && (chb.Checked) then
    rows.Add(ds.Tables(0).Rows(i))
  endif
endfor
Session["updateRows"] = rows;
end sub
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

mrongAuthor Commented:
Thalox,
I changed your code a little bit and no syntax error any more. I will test it soon.
For popup a window,  does it popup a new window everytime that page being reloaded?

Thanks.
0
ThaloxCommented:

i found out how to cast ;)


Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
dim ds as DataSet
ds = CType(Session["rowdata"], DataSet)
dim rows as ArrayList = new ArrayList()
dim i as integer

for  i = 0 to repeater.Items.Length - 1

  dim chb as CheckBox = CType(repeater.Items(i).findControl("chb"), CheckBox)
  if (chb != null) && (chb.Checked) then
    rows.Add(ds.Tables(0).Rows(i))
  endif
endfor
Session["updateRows"] = rows
end sub
0
ThaloxCommented:
it will popup a a window everytime yes.

if you need to prevent this you will have to set this in codebehind

<body <%= onLoadFunction %> >

codebehind

public onLoadFunction as String

sub page_load()

' check if there are data to display
if Session["rowdata"] = Nothing then
' do nothing
onLoadFunction = ""
else
onLoadFunction = "onload=\"window.open('updateRows.aspx')\""
endif
end sub

you will have to remove the rows from the session to disable the popup, but I dont know enough about your program to say anything about where to do this...
0
mrongAuthor Commented:
Thalox,
I got error "End of statement expected".

Sub page_load()

        ' check if there are data to display
        If Session("rowdata") Is Nothing Then
            ' do nothing
            onLoadFunction = ""
        Else
        onLoadFunction = "onload=\"window.open('Email.aspx')\""    <--------error here
        End If
    End Sub

BTW, how to remove the orws from the session?
0
ThaloxCommented:
the error is because c# <> vb

try this

onLoadFunction = "onload=""window.open('Email.aspx')"""

to remove it from session
Session.Remove("rowdata")
0
mrongAuthor Commented:
Thalox,

I tested the code, but it didn't popup the window which it suppose to...
Please let me know if you need me to post any function.
Thanks.
0
mrongAuthor Commented:
Thalox,
My bad. It did popup the window but got error on the poup window. Saying "DataBinding 'System.Data.DataRow' does not contain a property with the name 'proposal'".
'proposal' is the a database field which I retrieved from SQL stmt.

in my code I have
/load data from the database
MyOracleAdapt.Fill(MyOracleDS)
Session("MyDS") = MyOracleDS

 ds = CType(Session("MyDS"), DataSet)
        Dim rows As New ArrayList()

//in the update stmt, I have the following. Session("updateRows") is being pass to the popup window.
 rows.Add(ds.Tables(0).Rows(i))
 Session("updateRows") = rows
0
ThaloxCommented:

sorry cant try this, but I think the databinder doesn't "recognize" a list of datarows the same as datarows in a datatable and so databinding works different there.

you could try to store a whole dataset with the rows in the session, not only the rows.

something like this (syntax errors not excluded ;)):

Dim updDs as DataSet = new DataSet()
Dim tab  as DataTable = new DataTable()
updDs.Tables.Add(tab)
' assign column from original dataset-table to new one
tab.Columns = ds.Tables(0).Columns
' add rows
tab.Rows.Add(ds.Tables(0).Rows(i).ItemArray)
' store in session
Session("updateRows") = updDs


hope this helps

Thalox

0
mrongAuthor Commented:
Thalox,
Thank you for your post.
How to assign column from original dataset-table to new one in VB.net?

Thanks.

0
mrongAuthor Commented:
I treid your code below but didn't work.
tab.Columns = ds.Tables(0).Columns
0
ThaloxCommented:
ah, yepp cannot assign table.Columns

try this

' go through columns and create a new one with its settings
for(int i = 0; i < ds.Tables(0).Columns.Count; i++)
{
      DataColumn col = (DataColumn)ds.Tables(0).Columns(i)
      tab.Columns.Add(new DataColumn(col.ColumnName, col.DataType))
}
0
mrongAuthor Commented:
Thalox,

Below is what I have. It runs for the first time then gave me message "A column named 'proposal' already belongs to this DataTable". I guess I have to clean the table everytime....How to do it? Thanks.

 Dim col As New System.Data.DataColumn
                    Dim j
                    For j = 0 To ds.Tables(0).Columns.Count - 1
                        col = ds.Tables(0).Columns(j)
                        tab.Columns.Add(New DataColumn(col.ColumnName, col.DataType))
                    Next
                    tab.Rows.Add(ds.Tables(0).Rows(i).ItemArray)
0
ThaloxCommented:
tab.Columns.Clear()
0
mrongAuthor Commented:
I added the following code but still got the same error msg.
tab.Columns.Clear()
tab.Rows.Clear()
updDs.Clear()
0
ThaloxCommented:

try to debug your app and see what is in tab.Columns before you add a new one, and what is in col (in the for loop)

what do you mean with "It runs for the first time " the whole sub (displays the rows) or only the first round in your for loop?
0
mrongAuthor Commented:
When I tested the app first time, it didn't give me any error. After that, it always say "A column named 'proposal' already belongs to this DataTable".
0
ThaloxCommented:

then either  tab.Columns is not empty before the for loop or ds.Tables(0).Columns(j)
points to the same col every time.
does i increment each run in the for loop automatically?
0
mrongAuthor Commented:
I think the problem is caused by the index
Below is what I have for now. Do I need another loop for row(i)?
 tab.Columns.Clear()

                    tab.Rows.Clear()
                    Dim col As New System.Data.DataColumn
                    Dim j
                    For j = 0 To ds.Tables(0).Columns.Count - 1
                        tab.Columns.Add(New DataColumn(col.ColumnName, col.DataType))
                        col = ds.Tables(0).Columns(j)              
                    Next
                    tab.Rows.Add(ds.Tables(0).Rows(i).ItemArray)
0
ThaloxCommented:
do you do this within the loop to add the rows?

this is wrong.

first create the table with columns

tab.Rows.Clear()
                    Dim col As New System.Data.DataColumn
                    Dim j
                    For j = 0 To ds.Tables(0).Columns.Count - 1
                        tab.Columns.Add(New DataColumn(col.ColumnName, col.DataType))
                        col = ds.Tables(0).Columns(j)              
                    Next

then insert the rows in another loop

for  i = 0 to repeater.Items.Length - 1

  dim chb as CheckBox = CType(repeater.Items(i).findControl("chb"), CheckBox)
  if (chb != null) && (chb.Checked) then
    tab.Rows.Add(ds.Tables(0).Rows(i))
  endif
endfor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrongAuthor Commented:
Thomax,
I did exactly as you suggested above got error "This row already belongs to another table" at the following line.
 tab.Rows.Add(ds.Tables(0).Rows(i))

If I use  tab.Rows.Add(ds.Tables(0).Rows(i).ItemArray), I gto error "The string was not recognized as a valid DateTime. There is a unknown word starting at index 5"
0
ThaloxCommented:
sorry, copy + paste this loop from my comment before, ... itemarray is right.

the other error is because one of your datetime values is somehow no date.

try to change the row

tab.Columns.Add(New DataColumn(col.ColumnName, col.DataType))

to

tab.Columns.Add(New DataColumn(col.ColumnName, typeof(string)))          ' not sure if this is right for vb, means all columns have datatype string

this should at least display the data
0
mrongAuthor Commented:
Thalox,
In vb, the syntax is the following.
tab.Columns.Add(New DataColumn(col.ColumnName, GetType(String)))

Two more things.
1. The window still popup when I refresh the window(not re-submit).
I followed your instruction.
In Page_load I have the following:
If Session("updateRows") Is Nothing Then
            ' do nothing
            onLoadFunction = ""
        Else
            onLoadFunction = "onload=""window.open('Email.aspx')"""
        End If

In Update function I have:
Session("updateRows") = updDs
Response.Redirect("Report.aspx?shop=" & Session("shop"))
Session.Remove("updateRows")

I thought this will remove the session once submitted the form, but it didn't work.

2.The window popup....but it didn't show me the field("proposal") as I like..instead it shows me a day field which I have no diea where it from.
in the code-behind of popup window I have the following.
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Repeater5.DataSource = Session("updateRows")
            Repeater5.DataBind()
        End If
    End Sub
on aspx I have the following:
 <td><div align=left><%#DataBinder.Eval(Container.DataItem, "proposal")%></td>

Btw, it always show me one row on the popup windw  even I selected multiple rows from the previous page.

Thank you for your help.




       

0
mrongAuthor Commented:
Tholax,
I have fixed problem 1 above and working on Problem 2 now.
Thanks.
0
ThaloxCommented:
I think you should make more use of the debugger.

check what rows are added to the update dataset and with which values
also check what you get from from the session in the popup window. how many rows are there (as many as written into this dataset?) and what values are there, especially in the proposal column
0
mrongAuthor Commented:
Thalox,

I tried to debug it but got forbidden message..I am running remotely from the server.
I guess it should be much easier if I can watch what is happening thru the code.
Any Suggestions?

How to check what I am getting from the session?

Thanks.
0
ThaloxCommented:

In ancient times one wrote everything need to know directly in the page ;)
thats the only way I can think of.
declare a label in your page and wrote to it what you need.

but I think it would be much easier to develop local (with debugging) and port it to the server when it is done.

0
mrongAuthor Commented:
Thalox,
The column problem has been fixed..now the problem is the row.
Instead giving me the row I selected from the previous window...it gives me the top row of the refreshed page.
0
ThaloxCommented:

how do you fill the repeater to display the rows you select from?
make sure you dont refill the repeater on postback

if not IsPostBack then
' fill data
...
endif

when you fill the update ds:
is Repeater.Items.Length the same as the number of rows displayed?
does the loop go through each row?
do you find the checkbox-control for every row? if so, is it checked (and are the same rows checked as you did in the browser?)

what do you mean with "refreshed page"?

0
mrongAuthor Commented:
Say I have 5 rows in form1, and I selected top 2 rows on form1. After I submit form1, I have bottom 3 rows(left over) in form1. In form2(popup form), I have top 2 rows of those 3 left over on form1.
No sure what's going on.

0
mrongAuthor Commented:
Below is my page_load in form1

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session("updateRows") Is Nothing Then
            onLoadFunction = ""
        Else
            onLoadFunction = "onload=""window.open('Email.aspx')"""

        End If

        Session.Remove("updateRows")
        Session("shop") = Trim(Request.QueryString("shop"))
        Session("MyName") = Request.Cookies("MyName")
        If Request.Cookies("MyName") Is Nothing Then
            Response.Redirect("login.asp")
        End If

        If Not Me.IsPostBack Then

            Dim sqlText As String = "MySQL here...."
            Dim MyOracleConn As New System.Data.OracleClient.OracleConnection("Data Source=DB;Persist Security Info=True;User ID=ROOT;Password=PWD;Unicode=True")

            Dim MyOracleCMD As New System.Data.OracleClient.OracleCommand(sqlText)

            MyOracleCMD.Connection = MyOracleConn

            Dim MyOracleAdapt As New System.Data.OracleClient.OracleDataAdapter(MyOracleCMD)
            Dim MyOracleDS As New System.Data.DataSet()

            MyOracleAdapt.Fill(MyOracleDS)

            If MyOracleDS.Tables(0).Rows.Count = 0 Then
                Server.Transfer("none.aspx")
            End If
            Repeater1.DataSource = MyOracleDS
            Repeater1.DataBind()
            Session("MyDS") = MyOracleDS
        End If

    End Sub
0
mrongAuthor Commented:
Below is what I have for Update-Click on form1

Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click

        Dim ds As New System.Data.DataSet()
        ds = CType(Session("MyDS"), DataSet)

        Dim rows As New ArrayList()

        Dim updDs As DataSet = New DataSet()
        Dim tab As DataTable = New DataTable()
        updDs.Tables.Add(tab)
        tab.Rows.Clear()
        tab.Columns.Clear()
        Dim col As New System.Data.DataColumn
        Dim j
        For j = 0 To ds.Tables(0).Columns.Count - 1
            col = ds.Tables(0).Columns(j)
            tab.Columns.Add(New DataColumn(col.ColumnName, GetType(String)))
        Next
        Dim i

        For i = 0 To Repeater1.Items.Count - 1
            Dim attControl As CheckBox

            attControl = Repeater1.Items(i).FindControl("closeCase")
            If (attControl.Checked) Then
                Dim sqlText As String = "select key_value from ae_s_lck_e where key_value=Trim('" & attControl.ToolTip.ToString & "')"
                Dim MyOracleConn As New System.Data.OracleClient.OracleConnection("Data Source=FME;Persist Security Info=True;User ID=ROOT;Password=XXXXXXXXX;Unicode=True")
                Dim MyOracleCMD As New System.Data.OracleClient.OracleCommand(sqlText)
                MyOracleCMD.Connection = MyOracleConn
                Dim MyOracleAdapt As New System.Data.OracleClient.OracleDataAdapter(MyOracleCMD)
                Dim MyOracleDS As New System.Data.DataSet()
                MyOracleAdapt.Fill(MyOracleDS)
                If MyOracleDS.Tables(0).Rows.Count = 0 Then
                    Dim sqlText6 = "Update .."
                    Dim MyOracleConn6 As New System.Data.OracleClient.OracleConnection("Data Source=DB;Persist Security Info=True;User ID=ROOT;Password=PWD;Unicode=True")

                    Dim MyOracleCMD6 As New System.Data.OracleClient.OracleCommand(sqlText6, MyOracleConn6)
                    MyOracleConn6.Open()
                    MyOracleCMD6.ExecuteNonQuery()
                    MyOracleConn6.Close()

                    Dim sqlText7 = "SQL.."
                    Dim MyOracleConn7 As New System.Data.OracleClient.OracleConnection("Data Source=DB;Persist Security Info=True;User ID=ROOT;Password=PWD;Unicode=True")

                    Dim MyOracleCMD7 As New System.Data.OracleClient.OracleCommand(sqlText7, MyOracleConn7)
                    MyOracleConn7.Open()
                    MyOracleCMD7.ExecuteNonQuery()
                    MyOracleConn7.Close()

                    tab.Rows.Add(ds.Tables(0).Rows(i).ItemArray)

                Else
                End If
            End If
        Next

        GridView1.DataSource = updDs
        GridView1.DataBind()

        Session("updateRows") = updDs
        Session("updateRows1") = Session("updateRows")
        Response.Redirect("Report.aspx?shop=" & Session("shop"))

    End Sub
0
mrongAuthor Commented:
Thanks MASQUERAID !
0
mrongAuthor Commented:
Thalox,
I think I found out what caused the problem. On my repeater I always sort the data before click on "update", therefore order of the row is different once it is sorted.
Is it possible to add repeater items to the dataset? Something similiar like below?
 tab.Rows.Add(Repeater1.Items(i).DataItem)

Thanks.

0
ThaloxCommented:

I would never have found that out with your posts ;)

you should be able to do this, something like this

Dim data as DataRowView = CType(DataRowView, Repeater1.Items(i).DataItem)

tab.Rows.Add(data.ItemArray)


but it could be, that daatitem is null at this point.
if so you will have to store the index of each row in the dataset in the items of your repeater (with a hidden field or something..)
and then use the stored index to get the right data from the dataset
0
mrongAuthor Commented:
Thalox,
I am checking on the syntax, it game me errors.
0
mrongAuthor Commented:
I tried the following but doesn't work....
Dim Sdata As DataRowView = CType( Repeater1.Items(i).DataItem,DataRowView)
                    tab.Rows.Add(Sdata.Row.ItemArray)
0
ThaloxCommented:
what errors do you get?
if it is a nullreference-exception then probably the dataitem is null/nothing
0
mrongAuthor Commented:
The error message is "System.NullReferenceException: Object reference not set to an instance of an object" I thought I always select rows from the previous window...how can the datatiem be null/nothing?

Thanks.
0
mrongAuthor Commented:
How to store the index in the repeater and use it to get the right data from the dataset? Thanks.
0
ThaloxCommented:
the dataitem is only set in the databound event.

to find the right row in the dataset there are several methods.

I prefer to use the primarykey of the table your rows are from and store the value for each row in a hidden field in your repeateritem.
then you could do whatever you want with the rows (sort, ..) and when clicked on update get the value of the hidden field (the same way as the checked of the checkbox) and select the row from your dataset

dim rows as datarow()
set rows = ds.Tables(0).Select("id = '" & <ID_FROM_FIELD> & "'")

the right row should be rows(0)

0
mrongAuthor Commented:
what if I use more than one filed as ID? Thanks.
0
ThaloxCommented:

it doesnt matter, what you use as id. you have just to make sure, that the select statement will only return one (the right) row.
you could use more than one hidden field or combine all id field in one string
e.g    hiddenfield.value = id1 & "#" & id2 & "#" id3 ...
and then split it for the select statement
ids as string()
ids = hiddenfield.value.split('#')
ds.Tables(0).Select("id1 = '" & ids(0) & "' and id2 = '" & ids(1) & "'" ...)


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.