I currently have a table of data which is ordered in ID order, but i want the list to be ordered in descending order. This i am sure is a simple question but i just can not figure out how to do it.
Here is the ObjectDataSource etc. I am just not sure where to change the code...
Thanks
<asp:ObjectDataSource
ID="odsTours"
runat="server"
SelectMethod="GetFiltered"
TypeName="blive.Shop.Tour"
SortParameterName="sortExpression">
<SelectParameters>
<asp:Parameter
Name="isActive"
ConvertEmptyStringToNull="true"
DefaultValue="" />
<asp:Parameter
Name="isInThePast"
ConvertEmptyStringToNull="true"
DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource
ID="odsBookings"
runat="server"
SelectMethod="GetFiltered"
TypeName="blive.Shop.Booking"
SortParameterName="sortExpression">
<SelectParameters>
<asp:ControlParameter
ControlID="ddlTourFilter"
PropertyName="SelectedValue"
Name="tourId"
Type="Int32"
ConvertEmptyStringToNull="true" />
<asp:Parameter
Name="username"
ConvertEmptyStringToNull="true"
DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
It should be done in the select method of the object data source.
In your case it should be in
GetFiltered method.
You can apply the order by in this method.
Related
Similar to F12 hotkey from code, I would like to go to the method that is used in the markup, eg.
<asp:ObjectDataSource ID="dsADDOCs" runat="server" SelectMethod="DataSet_SelectForProject"
TypeName="DataLogic.tADDOCList" OnSelecting="dsADDOCs_Selecting">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="iORDRID" Type="Int32" />
<asp:Parameter DefaultValue="" Name="iAccesses" ConvertEmptyStringToNull="true" Type="String" />
<asp:Parameter Name="iTracer" Type="String" ConvertEmptyStringToNull="true" DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
So here if I would ctrl+click or F12 on dsADDOCs_Selecting, than it would go to the codebehind to the dsADDOCs_Selecting method, or when I do the same on DataSet_SelectForProject, than it would open DataSet_SelectForProject method in DataLogic.tADDOCList
Is there an option, plugin or anything to do this? It would be really helpful.
In my ASP.NET web forms I find that the ObjectDataSource won't update/refresh when the SelectParameter values do not change.
How do I force refresh an ObjectDataSource regardless of whether or not the parameter values change?
Example code:
<asp:ObjectDataSource ID="odsUserSearchResults" runat="server"
SelectMethod="GetData" EnablePaging="false"
TypeName="MySolution.ObjectDataSources.Users">
<SelectParameters>
<asp:ControlParameter Name="name" ControlID="txtName" PropertyName="Text" Type="String" />
<asp:ControlParameter Name="statusId" ControlID="ddlStatus" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
You need to disable the object data source view state by setting the EnableViewState property to false, like so:
<asp:ObjectDataSource ID="odsUserSearchResults" EnableViewState="false" runat="server"
SelectMethod="GetData" EnablePaging="false"
TypeName="MySolution.ObjectDataSources.Users">
<SelectParameters>
<asp:ControlParameter Name="name" ControlID="txtName" PropertyName="Text" Type="String" />
<asp:ControlParameter Name="statusId" ControlID="ddlStatus" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
When working with ObjectDataSource I have following select:
<asp:DropDownList runat="server" SelectedValue='<%# Bind("InceptionCycle.ID") %>' ID="InceptionCycle"
DataSourceID="odsAllCycles" DataTextField="CycleName" DataValueField="ID" AppendDataBoundItems="true">
<asp:ListItem Text="Choose..." Value=""></asp:ListItem>
</asp:DropDownList>
and ObjectDataSource configured with UpdateMethod and InsertMethod. However insert/update methods have parameters with InceptionCycle name (because InceptionCycle.ID is not valid identifier).
Is there a way to instruct ObjectDataSource to take InceptionCycle.ID form parameter and place in as InceptionCycle method parameter?
Here's full ObjectDataSource code:
<asp:ObjectDataSource ID="ods" runat="server" TypeName="Sources.DomainSource"
SelectMethod="FindById" InsertMethod="Add" UpdateMethod="Update"
OnInserted="ods_Inserted" OnUpdated="ods_Updated">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
</SelectParameters>
<InsertParameters>
<asp:Parameter ConvertEmptyStringToNull="true" Name="ShortTitle" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="WMRId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="MDSId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="Status" />
</InsertParameters>
<UpdateParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="ShortTitle" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="WMRId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="MDSId" />
<asp:Parameter ConvertEmptyStringToNull="true" Name="Status" />
</UpdateParameters>
</asp:ObjectDataSource>
You can only use the Bind syntax with a top level property - it doesn't support nested properties (VS 2012 will, though).
So, you should create a new property on your data source like below and bind the SelectedValue to this new property instead
public string InceptionCycleID
{
get
{
return InceptionCycle.ID;
}
set
{
InceptionCycle.ID = value;
}
}
Issue: I have 2 datasources declared on my .aspx file as shown below:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="UsuarioDelete" SelectMethod="SelectMyAllNotME_Data" TypeName="BLLayer.Usuarios" OnInserted="ObjectDataSource_Inserted">
<DeleteParameters>
<asp:ControlParameter ControlID="ConfirmDialogBox1" Name="id_usuario" PropertyName="Aceptar_CommandName" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter DefaultValue="1" Name="id_usuario" SessionField="id_usuario" Type="Int32" />
<asp:SessionParameter DefaultValue="1" Name="id_pais" SessionField="id_pais" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DeleteMethod="UsuarioDelete" SelectMethod="SelectMyAllNotME_Data" TypeName="BLLayer.Usuarios" OnInserted="ObjectDataSource_Inserted">
<DeleteParameters>
<asp:ControlParameter ControlID="ConfirmDialogBox1" Name="id_usuario" PropertyName="Aceptar_CommandName" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="id_emp" QueryStringField="id_emp" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
The method "SelectMyAllNotME_Data" is an overloaded method that in one he receives 2 values and in the other just one value, it is used to filter the information.
What I want to do is than in my onLoadPage method is something like this:
if (Request.QueryString["id_emp"] != null)
{
GridViewUsers.DataSource = ObjectDataSource2.SelectMethod;
GridViewUsers.DataMember = ObjectDataSource2.SelectMethod;
}
else
{
GridViewUsers.DataSource = ObjectDataSource1.SelectMethod;
GridViewUsers.DataMember = ObjectDataSource1.SelectMethod;
}
}
I've already tried this, but it isn't working, can anyone help me please?
You should call
GridViewUsers.DataBind();
on the datasource in aspx just do
EnablePaging="true"
So I'm trying to update my GridView, and I get this error:
You have specified that your update command compares all values on
SqlDataSource 'SqlDataSource1', but the dictionary passed in for
oldValues is empty. Pass in a valid dictionary for update or change
your mode to OverwriteChanges.
Here is the SQL Data Source in question:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT field1, field2, field3, field4, field5, field6
FROM table
ORDER BY field4"
UpdateCommand="UPDATE table2
SET field2 = #field2 , field3 = #field3, field4 = #field4
WHERE (field1 = #original_field1) AND (field6 = #original_field6)"
FilterExpression="field1 LIKE '{0}'">
<FilterParameters>
<asp:ControlParameter ControlID="SearchBox" Name="field1" Type="String" DefaultValue="" />
</FilterParameters>
<SelectParameters>
<asp:ControlParameter ControlID="SearchBox" Name="field1" Type="String" DefaultValue="" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="field2" Type="String" />
<asp:Parameter Name="field3" Type="String" />
<asp:Parameter Name="field4" Type="Int32" />
<asp:Parameter Name="original_field1" Type="String" />
<asp:Parameter Name="original_field5" Type="Int32" />
<asp:Parameter Name="original_field2" Type="String" />
<asp:Parameter Name="original_field3" Type="String" />
<asp:Parameter Name="original_field4" Type="Int32" />
<asp:Parameter Name="original_field6" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
Now I understand one way to get around this is to change 'CompareAllValues' to 'OverwriteChanges', however I have never needed to do this before (I have other GridViews on the page that update just fine) and it never seems to update the data when I DO try anyway.
Is it the nature of the data that would cause this Data Source to act differently to the rest? Or have I done something stupid?
Thanks! :)
I discovered the answer! The data field 'field6' was not included in my Gridview as a field.
Once I added it as a column in the GridView I was able to make it work :)
(Can also add it as a DataKeyName)