Crashing caused by Dropdownlist in Header template
Crashing caused by Dropdownlist in Header template
am 20.12.2007 21:11:00 von BChernick
I've been looking at references about this all afternoon but I can't really
see anything that seems relevant to my particular situation.
I have a gridview. This is used in read-only mode only, strictly for
display and deletes. Paging is on. I turned a column into a template and
put a dropdown list in the header template. The values of this dropdown are
read from a list of fixed values stored in a table other than the one bound
to the grid. The setting of the dropdown controls the FilterExpression of
the grids ObjectDataSource. If the FilterExpression is blank there is no
problem at all. Otherwise the filtering action of the ddl works fine until I
try to page the gridview. If I try to page the gridview with a filter
setting the page crashes with the message:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.
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.InvalidOperationException: Databinding methods
such as Eval(), XPath(), and Bind() can only be used in the context of a
databound control.
Source Error:
Line 30:
Line 31:
Line 32:
Line 33:
Line 34:
RE: Crashing caused by Dropdownlist in Header template
am 20.12.2007 21:31:01 von BChernick
Once again, I may have appended too soon. Once again, I have to ask: This
works. Why? (Or at least is this the best solution?)
I put the following code in the GridView's PageIndexChanged and RowDeleted
event handlers:
ObjectDataSource1.FilterExpression = "RK_Unit=" + Session("UnitFilter")
If ObjectDataSource1.FilterExpression <> "" Then
GridView1.DataBind()
End If
(Not sure why I have to restore the ODS's FilterExpression. Wouldn't the
ODS's FilterExpression be retained in the view state? And I don't think it's
being accidentally cleared anywhere.)
"B. Chernick" wrote:
> I've been looking at references about this all afternoon but I can't really
> see anything that seems relevant to my particular situation.
>
> I have a gridview. This is used in read-only mode only, strictly for
> display and deletes. Paging is on. I turned a column into a template and
> put a dropdown list in the header template. The values of this dropdown are
> read from a list of fixed values stored in a table other than the one bound
> to the grid. The setting of the dropdown controls the FilterExpression of
> the grids ObjectDataSource. If the FilterExpression is blank there is no
> problem at all. Otherwise the filtering action of the ddl works fine until I
> try to page the gridview. If I try to page the gridview with a filter
> setting the page crashes with the message:
>
> Databinding methods such as Eval(), XPath(), and Bind() can only be used in
> the context of a databound control.
> 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.InvalidOperationException: Databinding methods
> such as Eval(), XPath(), and Bind() can only be used in the context of a
> databound control.
>
> Source Error:
>
> Line 30:
> Line 31:
> Line 32:
> Line 33:
> Line 34:
>
>
RE: Crashing caused by Dropdownlist in Header template
am 21.12.2007 05:14:00 von MohamadElarabiMCPD
I need more information to try and answer this. Please make sure to answer
each question.
1- I'm confused by your subject and your preface. What made you believe that
this is caused by the DropDown? The error seems to be not related to the drop
down.
2- Is ObjectDataSource1 the DS for the drop down or the grid view? Seems to
be the DS for the GridView.
3- Is it possible to paste over your complete
... tag?
Thanks,
P.S. The if statement that checks if FilterExpression <> "" will always
return true since you're hardcoding "RK_Unit=" into the FilterExpression in
the previous line. To avoid an error in your bind you might need to check If
Session("UnitFilter") <> "" instead and if it is true then set the
FilterExpression and Bind.
----
Mohamad Elarabi
MCP, MCTS, MCPD.
"B. Chernick" wrote:
> Once again, I may have appended too soon. Once again, I have to ask: This
> works. Why? (Or at least is this the best solution?)
>
> I put the following code in the GridView's PageIndexChanged and RowDeleted
> event handlers:
>
> ObjectDataSource1.FilterExpression = "RK_Unit=" + Session("UnitFilter")
> If ObjectDataSource1.FilterExpression <> "" Then
> GridView1.DataBind()
> End If
>
> (Not sure why I have to restore the ODS's FilterExpression. Wouldn't the
> ODS's FilterExpression be retained in the view state? And I don't think it's
> being accidentally cleared anywhere.)
>
> "B. Chernick" wrote:
>
> > I've been looking at references about this all afternoon but I can't really
> > see anything that seems relevant to my particular situation.
> >
> > I have a gridview. This is used in read-only mode only, strictly for
> > display and deletes. Paging is on. I turned a column into a template and
> > put a dropdown list in the header template. The values of this dropdown are
> > read from a list of fixed values stored in a table other than the one bound
> > to the grid. The setting of the dropdown controls the FilterExpression of
> > the grids ObjectDataSource. If the FilterExpression is blank there is no
> > problem at all. Otherwise the filtering action of the ddl works fine until I
> > try to page the gridview. If I try to page the gridview with a filter
> > setting the page crashes with the message:
> >
> > Databinding methods such as Eval(), XPath(), and Bind() can only be used in
> > the context of a databound control.
> > 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.InvalidOperationException: Databinding methods
> > such as Eval(), XPath(), and Bind() can only be used in the context of a
> > databound control.
> >
> > Source Error:
> >
> > Line 30:
> > Line 31:
> > Line 32:
> > Line 33:
> > Line 34:
> >
> >
RE: Crashing caused by Dropdownlist in Header template
am 21.12.2007 15:16:00 von BChernick
1. That's just it. This is the startup page, a very vanilla grid with
almost no code until I started trying to install a dropdown. Just bind the
gridview to a data source and display. It's always in ReadOnly mode. On the
surface I can't see any way the ddl could cause this problem. (Could the
problem be caused by having the ddl's ODS included within the header
template?)
2. Yes, ObjectDataSource1 is the ods for the grid.
Actually I did modify the code slightly. The event handlers now all do it
this way:
If Session("UnitFilter") <> "" Then
ObjectDataSource1.FilterExpression = "RK_Unit=" +
Session("UnitFilter")
GridView1.DataBind()
End If
Here's the complete html of the page:
<%@ Page Language="vb" MasterPageFile="~/Site1.Master"
AutoEventWireup="false" Codebehind="Default.aspx.vb"
Inherits="GM_Project_Application_2._Default" Theme="default" %>
ContentPlaceHolderID="ContentPlaceHolder1">
AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="PK" DataSourceID="ObjectDataSource1"
ForeColor="#333333"
GridLines="None" Width="100%" PageSize="15" AllowSorting="True">
InsertVisible="False" ReadOnly="True"
SortExpression="PK" Visible="False" />
Text="Unit">
DataSourceID="ObjectDataSourceUnit"
DataTextField="Item" DataValueField="PK"
AutoPostBack="True" OnPreRender="SetValue"
OnDataBound="ddlUnit_DataBound"
OnSelectedIndexChanged="ddlUnit_SelectedIndexChanged">
ID="ObjectDataSourceUnit" runat="server"
OldValuesParameterFormatString="{0}"
SelectMethod="GetData"
TypeName="GM_Project_Application_2.GMPATableAdapters.ztblPic klistTableAdapter">
Name="Group" Type="String" />
SortExpression="RK_PG">
SortExpression="ID">
SortExpression="Name">
HeaderText="Classification" SortExpression="RK_Class">
HeaderText="G0 Date"
SortExpression="G0" HtmlEncode="False">
DataNavigateUrlFormatString="ListItems.aspx?ProjectId={0}"
HeaderText="Project Details" Text="View Details">
HorizontalAlign="Center" />
ForeColor="#333333" />
DeleteMethod="Delete"
InsertMethod="Insert" OldValuesParameterFormatString="{0}"
SelectMethod="GetData"
TypeName="GM_Project_Application_2.GMPATableAdapters.tblProj ectTableAdapter"
UpdateMethod="Update">
NavigateUrl="ListItems.aspx?ProjectId=-1">Add Project
|
NavigateUrl="~/DisplayEmployees.aspx"
Visible="False">View Employees
|
"Mohamad Elarabi [MCPD]" wrote:
> I need more information to try and answer this. Please make sure to answer
> each question.
>
> 1- I'm confused by your subject and your preface. What made you believe that
> this is caused by the DropDown? The error seems to be not related to the drop
> down.
>
> 2- Is ObjectDataSource1 the DS for the drop down or the grid view? Seems to
> be the DS for the GridView.
>
> 3- Is it possible to paste over your complete
> ... tag?
>
> Thanks,
>
> P.S. The if statement that checks if FilterExpression <> "" will always
> return true since you're hardcoding "RK_Unit=" into the FilterExpression in
> the previous line. To avoid an error in your bind you might need to check If
> Session("UnitFilter") <> "" instead and if it is true then set the
> FilterExpression and Bind.
> ----
> Mohamad Elarabi
> MCP, MCTS, MCPD.
>
>
> "B. Chernick" wrote:
>
> > Once again, I may have appended too soon. Once again, I have to ask: This
> > works. Why? (Or at least is this the best solution?)
> >
> > I put the following code in the GridView's PageIndexChanged and RowDeleted
> > event handlers:
> >
> > ObjectDataSource1.FilterExpression = "RK_Unit=" + Session("UnitFilter")
> > If ObjectDataSource1.FilterExpression <> "" Then
> > GridView1.DataBind()
> > End If
> >
> > (Not sure why I have to restore the ODS's FilterExpression. Wouldn't the
> > ODS's FilterExpression be retained in the view state? And I don't think it's
> > being accidentally cleared anywhere.)
> >
> > "B. Chernick" wrote:
> >
> > > I've been looking at references about this all afternoon but I can't really
> > > see anything that seems relevant to my particular situation.
> > >
> > > I have a gridview. This is used in read-only mode only, strictly for
> > > display and deletes. Paging is on. I turned a column into a template and
> > > put a dropdown list in the header template. The values of this dropdown are
> > > read from a list of fixed values stored in a table other than the one bound
> > > to the grid. The setting of the dropdown controls the FilterExpression of
> > > the grids ObjectDataSource. If the FilterExpression is blank there is no
> > > problem at all. Otherwise the filtering action of the ddl works fine until I
> > > try to page the gridview. If I try to page the gridview with a filter
> > > setting the page crashes with the message:
> > >
> > > Databinding methods such as Eval(), XPath(), and Bind() can only be used in
> > > the context of a databound control.
> > > 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.InvalidOperationException: Databinding methods
> > > such as Eval(), XPath(), and Bind() can only be used in the context of a
> > > databound control.
> > >
> > > Source Error:
> > >
> > > Line 30:
> > > Line 31:
> > > Line 32:
> > > Line 33:
> > > Line 34:
> > >
> > >
RE: Crashing caused by Dropdownlist in Header template
am 21.12.2007 20:37:01 von MohamadElarabiMCPD
Ok, This seems correct. You have to re-bind the GridView to its datasource
after the page index changes. The paging functionality doesn't work out of
the box by just setting AllowPaging=True. So given that, your code that you
adjusted, you have to take the GridView1.DataBind() out of the if statement.
You must bind in all paths. So I think it should be like this
If Session("UnitFilter") <> "" Then
ObjectDataSource1.FilterExpression = "RK_Unit=" +
Session("UnitFilter")
Else
ObjectDataSource1.FilterExpression = "" 'To clear any previous
values
End If
GridView1.DataBind()
The rest of your code are fine. I'd just recommend taking the
ObjectDataSourceUnit out of the headertemplate and all the way outside the
GridView tag, but this is just for readability. I usually put all my
datasource tags in one area either the top or the bottom of the page.
Good luck.
--
Mohamad Elarabi
MCP, MCTS, MCPD.
"B. Chernick" wrote:
> 1. That's just it. This is the startup page, a very vanilla grid with
> almost no code until I started trying to install a dropdown. Just bind the
> gridview to a data source and display. It's always in ReadOnly mode. On the
> surface I can't see any way the ddl could cause this problem. (Could the
> problem be caused by having the ddl's ODS included within the header
> template?)
>
> 2. Yes, ObjectDataSource1 is the ods for the grid.
>
> Actually I did modify the code slightly. The event handlers now all do it
> this way:
>
> If Session("UnitFilter") <> "" Then
> ObjectDataSource1.FilterExpression = "RK_Unit=" +
> Session("UnitFilter")
> GridView1.DataBind()
> End If
>
> Here's the complete html of the page:
>
> <%@ Page Language="vb" MasterPageFile="~/Site1.Master"
> AutoEventWireup="false" Codebehind="Default.aspx.vb"
> Inherits="GM_Project_Application_2._Default" Theme="default" %>
>
>
> ContentPlaceHolderID="ContentPlaceHolder1">
>
>
> AutoGenerateColumns="False"
> CellPadding="4" DataKeyNames="PK" DataSourceID="ObjectDataSource1"
> ForeColor="#333333"
> GridLines="None" Width="100%" PageSize="15" AllowSorting="True">
>
>
>
>
>
> InsertVisible="False" ReadOnly="True"
> SortExpression="PK" Visible="False" />
>
>
>
>
>
>
> Text="Unit">
>
> DataSourceID="ObjectDataSourceUnit"
> DataTextField="Item" DataValueField="PK"
> AutoPostBack="True" OnPreRender="SetValue"
> OnDataBound="ddlUnit_DataBound"
> OnSelectedIndexChanged="ddlUnit_SelectedIndexChanged">
>
> ID="ObjectDataSourceUnit" runat="server"
> OldValuesParameterFormatString="{0}"
> SelectMethod="GetData"
> TypeName="GM_Project_Application_2.GMPATableAdapters.ztblPic klistTableAdapter">
>
>
> Name="Group" Type="String" />
>
>
>
>
>
>
>
>
>
>
> SortExpression="RK_PG">
>
>
>
>
> SortExpression="ID">
>
>
>
>
>
>
>
>
> SortExpression="Name">
>
>
>
>
> HeaderText="Classification" SortExpression="RK_Class">
>
>
>
>
> HeaderText="G0 Date"
> SortExpression="G0" HtmlEncode="False">
>
>
>
>
> DataNavigateUrlFormatString="ListItems.aspx?ProjectId={0}"
> HeaderText="Project Details" Text="View Details">
>
>
>
>
>
> HorizontalAlign="Center" />
>
> ForeColor="#333333" />
>
>
>
>
>
> DeleteMethod="Delete"
> InsertMethod="Insert" OldValuesParameterFormatString="{0}"
> SelectMethod="GetData"
>
> TypeName="GM_Project_Application_2.GMPATableAdapters.tblProj ectTableAdapter"
> UpdateMethod="Update">
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> NavigateUrl="ListItems.aspx?ProjectId=-1">Add Project
> |
>
>
> NavigateUrl="~/DisplayEmployees.aspx"
> Visible="False">View Employees
> |
>
>
>
>
>
>
> "Mohamad Elarabi [MCPD]" wrote:
>
> > I need more information to try and answer this. Please make sure to answer
> > each question.
> >
> > 1- I'm confused by your subject and your preface. What made you believe that
> > this is caused by the DropDown? The error seems to be not related to the drop
> > down.
> >
> > 2- Is ObjectDataSource1 the DS for the drop down or the grid view? Seems to
> > be the DS for the GridView.
> >
> > 3- Is it possible to paste over your complete
> > ... tag?
> >
> > Thanks,
> >
> > P.S. The if statement that checks if FilterExpression <> "" will always
> > return true since you're hardcoding "RK_Unit=" into the FilterExpression in
> > the previous line. To avoid an error in your bind you might need to check If
> > Session("UnitFilter") <> "" instead and if it is true then set the
> > FilterExpression and Bind.
> > ----
> > Mohamad Elarabi
> > MCP, MCTS, MCPD.
> >
> >
> > "B. Chernick" wrote:
> >
> > > Once again, I may have appended too soon. Once again, I have to ask: This
> > > works. Why? (Or at least is this the best solution?)
> > >
> > > I put the following code in the GridView's PageIndexChanged and RowDeleted
> > > event handlers:
> > >
> > > ObjectDataSource1.FilterExpression = "RK_Unit=" + Session("UnitFilter")
> > > If ObjectDataSource1.FilterExpression <> "" Then
> > > GridView1.DataBind()
> > > End If
> > >
> > > (Not sure why I have to restore the ODS's FilterExpression. Wouldn't the
> > > ODS's FilterExpression be retained in the view state? And I don't think it's
> > > being accidentally cleared anywhere.)
> > >
> > > "B. Chernick" wrote:
> > >
> > > > I've been looking at references about this all afternoon but I can't really
> > > > see anything that seems relevant to my particular situation.
> > > >
> > > > I have a gridview. This is used in read-only mode only, strictly for
> > > > display and deletes. Paging is on. I turned a column into a template and
> > > > put a dropdown list in the header template. The values of this dropdown are
> > > > read from a list of fixed values stored in a table other than the one bound
> > > > to the grid. The setting of the dropdown controls the FilterExpression of
> > > > the grids ObjectDataSource. If the FilterExpression is blank there is no
> > > > problem at all. Otherwise the filtering action of the ddl works fine until I
> > > > try to page the gridview. If I try to page the gridview with a filter
> > > > setting the page crashes with the message:
> > > >
> > > > Databinding methods such as Eval(), XPath(), and Bind() can only be used in
> > > > the context of a databound control.
> > > > 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.InvalidOperationException: Databinding methods
> > > > such as Eval(), XPath(), and Bind() can only be used in the context of a
> > > > databound control.
> > > >
> > > > Source Error:
> > > >
> > > > Line 30:
> > > > Line 31:
> > > > Line 32:
> > > > Line 33:
> > > > Line 34:
> > > >
> > > >