P
postings
Hi
I've got a nasty problem with my datagrid. Sorry for the long post,
but I am trying to be clear and compact here.
FYI - About my datagrid:
-------------------------------------------------------------------
I have in the datagrid and an EditCommandButton like so:
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
-------------------------------------------------------------------
There's also some drop down list boxes in the EditItemTemplate which
I am not populating with values until I hit the edit linkbutton. Note
that there are no controls are created dynamically in the datagrid.
The datagrid is set up and populated like so (triggered when somebody
hits a button to display it):
-------------------------------------------------------------------
Private Sub populateDGProductSummary()
SqlSelectProducts.CommandText = strQuery
Mydataset.ProductInvoiceSummary.Clear()
Mydataset.EnforceConstraints = False
MyDataAdapter.Fill(Mydataset.ProductInvoiceSummary)
MyDataGrid.DataSource = Mydataset.ProductInvoiceSummary
MyDataGrid.CurrentPageIndex = Session("DGPageProductSummary")
MyDataGrid.DataBind()
End Sub
-------------------------------------------------------------------
This works fine for the initial display (Note I am handling the opening
and closing of SQL just fine, I've just removed it from my code for
now).
SO FAR SO GOOD....
Now in the context of hitting the edit button and calling procudure and
repopulating datagrid using populateDGProductSummary again:
Everything works in my code (which you haven't seen yet). My drop down
listboxes work fine etc.
*** NEW SCENARIO THEN *** (hope you are still following)
What if I use the viewstate as a datasource rather than repopulate the
dataset bound to the datagrid (it's not incredibly efficient but it
will have to do )...
I have put in on the last line of populateDGProductSummary: subroutine:
-------------------------------------------------------------------
viewstate.Add("Datagriddata", DsContactStructure1)
-------------------------------------------------------------------
And here is the code for my Edit linkbutton:
-------------------------------------------------------------------
Private Sub DGProductSummary_Edit(ByVal source As System.Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
MyDataGrid.EditCommand
Response.Write("Triggered")
Mydataset.ProductInvoiceSummary.Clear()
Mydataset.EnforceConstraints = False
Dim dssaved As DataSet = CType(viewstate.Item("Datagriddata"), DataSet)
DAShowInvoiceProducts.Fill(dssaved)
MyDataGrid.DataSource = dssaved.Tables("ProductInvoiceSummary")
-------------------------------------------------------------------
So far so good (I can see the data if I iterate through the dataset
right now)....
*** THE PROBLEM **
The problem is when I populate the drop down lists in the datagrid
after this code. If I have just repopulated the datagrid with using
the original populateDGProductSummary() then there would be no
problems. It's when I get the viewstate for the datagrid instead.
My code then to populate the listbox:
-------------------------------------------------------------------
Dim ddl As DropDownList
ddl = MyDataGrid.Items(e.Item.ItemIndex).FindControl("ddlCurrency")
ddl.Items.Add(New ListItem("HELLO", "WORLD"))
-------------------------------------------------------------------
Basically it seems that I cant find the control ddlCurrency any more
using Viewstate, I get the error message on the findcontrol line:
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection. Parameter name:
index
Can anybody tell me what on earth is going on? Why can't I find the
control in this scenario?
Am I being thick?
Many thanks!!
Alex
(p.s. thanks for baring with me, if you read this far and still
understand what I'm going on about!)
I've got a nasty problem with my datagrid. Sorry for the long post,
but I am trying to be clear and compact here.
FYI - About my datagrid:
-------------------------------------------------------------------
I have in the datagrid and an EditCommandButton like so:
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
-------------------------------------------------------------------
There's also some drop down list boxes in the EditItemTemplate which
I am not populating with values until I hit the edit linkbutton. Note
that there are no controls are created dynamically in the datagrid.
The datagrid is set up and populated like so (triggered when somebody
hits a button to display it):
-------------------------------------------------------------------
Private Sub populateDGProductSummary()
SqlSelectProducts.CommandText = strQuery
Mydataset.ProductInvoiceSummary.Clear()
Mydataset.EnforceConstraints = False
MyDataAdapter.Fill(Mydataset.ProductInvoiceSummary)
MyDataGrid.DataSource = Mydataset.ProductInvoiceSummary
MyDataGrid.CurrentPageIndex = Session("DGPageProductSummary")
MyDataGrid.DataBind()
End Sub
-------------------------------------------------------------------
This works fine for the initial display (Note I am handling the opening
and closing of SQL just fine, I've just removed it from my code for
now).
SO FAR SO GOOD....
Now in the context of hitting the edit button and calling procudure and
repopulating datagrid using populateDGProductSummary again:
Everything works in my code (which you haven't seen yet). My drop down
listboxes work fine etc.
*** NEW SCENARIO THEN *** (hope you are still following)
What if I use the viewstate as a datasource rather than repopulate the
dataset bound to the datagrid (it's not incredibly efficient but it
will have to do )...
I have put in on the last line of populateDGProductSummary: subroutine:
-------------------------------------------------------------------
viewstate.Add("Datagriddata", DsContactStructure1)
-------------------------------------------------------------------
And here is the code for my Edit linkbutton:
-------------------------------------------------------------------
Private Sub DGProductSummary_Edit(ByVal source As System.Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
MyDataGrid.EditCommand
Response.Write("Triggered")
Mydataset.ProductInvoiceSummary.Clear()
Mydataset.EnforceConstraints = False
Dim dssaved As DataSet = CType(viewstate.Item("Datagriddata"), DataSet)
DAShowInvoiceProducts.Fill(dssaved)
MyDataGrid.DataSource = dssaved.Tables("ProductInvoiceSummary")
-------------------------------------------------------------------
So far so good (I can see the data if I iterate through the dataset
right now)....
*** THE PROBLEM **
The problem is when I populate the drop down lists in the datagrid
after this code. If I have just repopulated the datagrid with using
the original populateDGProductSummary() then there would be no
problems. It's when I get the viewstate for the datagrid instead.
My code then to populate the listbox:
-------------------------------------------------------------------
Dim ddl As DropDownList
ddl = MyDataGrid.Items(e.Item.ItemIndex).FindControl("ddlCurrency")
ddl.Items.Add(New ListItem("HELLO", "WORLD"))
-------------------------------------------------------------------
Basically it seems that I cant find the control ddlCurrency any more
using Viewstate, I get the error message on the findcontrol line:
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection. Parameter name:
index
Can anybody tell me what on earth is going on? Why can't I find the
control in this scenario?
Am I being thick?
Many thanks!!
Alex
(p.s. thanks for baring with me, if you read this far and still
understand what I'm going on about!)