Order By Desc is not working in SqlDataSource - asp.net

I'm using repeaters to show data in webform. But I have a problem with this code. when I select * data from BidTAble, it shows in Desc order, but when I use INNER JOIN, Desc doesn't work.! :/
Here i've uploaded a picture of BidTable content, i want Saim data on the top of table instead of Awais
Code:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CONN %>"
SelectCommand="SELECT BidTable.BidID, BidTable.RegID, BidTable.CarID, Reg.username, BidTable.BidAmount FROM [BidTable] INNER JOIN Reg ON BidTable.RegID = Reg.ID WHERE ([CarID] = #CarID) ORDER BY [BidTable].[BidAmount] DESC">
<SelectParameters>
<asp:QueryStringParameter Name="CarID"
QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

Related

ASP.Net Cascading DropDownLists disable on 1 ListItems / enable on 2 or more

I'm new to ASP and web technology- I've designed a cascading dropdownlist of 8 boxes. They all filter upon the prior boxes until you end up with one final selection. I'm wanting to disable the boxes if they have only one result - therefore showing the user that they don't need to select that box to look for an option, but to enable it if there's 2 results or more (since they might go back to a prior box and change the selection) and so they know they need to select something in this box.
I'm able to populate all the boxes automatically, but right now, users have to select each box one by one to ensure there's no other choices - this is something I want to avoid.
Below is a sample of box 5 (DDLCountry). The box before is DDLModel and the next box after will be DDLType.
Any help would be appreciated and I'm always glad for any feedback on improving how this works.
<%-- DropDown County --%>
<asp:DropDownList id="DDLCountry" runat="server" DataSourceID="SqlDataSource5" DataTextField="Country" DataValueField="Country" Height="27px" Width="160px" AutoPostBack="True" TabIndex="5">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" CancelSelectOnNullParameter="false" ConnectionString="<%$ ConnectionStrings:PartFinderConnection %>" SelectCommand="SELECT DISTINCT Models.Country, [CC Group List].[CC Grouped], Models.Make FROM [CC Group List] CCSort INNER JOIN [CC Group List] ON CCSort.[CC Grouped] = [CC Group List].[CC Grouped] INNER JOIN Models ON [CC Group List].CC = Models.CC WHERE [CC Group List].[CC Grouped] = #DDLCC AND Models.Make = #Make AND Models.Year = #DDLYear AND [Models].[Model Name] = #DDLModel ORDER BY Models.Country ASC;">
<SelectParameters>
<asp:ControlParameter ControlID="DDLCC" Name="DDLCC" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DDLMake" Name="Make" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DDLYear" Name="DDLYear" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DDLModel" Name="DDLModel" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

Using the same DataSource by some DropDownList

I have a stored procedure that gets a parameter and retrieves a list of suppliers from the database:
Create proc spGetSuppliers
(#RowMeterialID int)
as
begin
select distinct sName
from Supplier, RawMaterials, SupplierRawMaterials
where RawMaterials.rmID = #RowMeterialID
and RawMaterials.rmID = SupplierRawMaterials.rmID
end
A datasource :
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:igroup9_test1ConnectionString %>"
SelectCommand="spGetSuppliers" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="RowMeterialID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
And about 10 DropDownList that retrieve data from the database using the DataSource.
I want the first DropDownList to use the DataSource with Value=1 which should be sent to the stored procedure and the second DDL use the value=2 and so on.

FilterExpression search bar - multiple data types (int and varchar)

I have a textbox that I want to make into a search bar. My table has an int "id" and varchar(50) "name". I want to search for either the name or the id in the same textbox. Is that even possible? I've tried many things but haven't gotten to a solution yet.
Here's what I have:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:New_QuickBooksConnectionString %>"
SelectCommand="SELECT * FROM [Testing1]" FilterExpression="([id] = {0}) OR ([name] LIKE '%(CAST {0} AS VARCHAR(50))%')">
<FilterParameters>
<asp:ControlParameter ControlID="TextBox1" Name="id" PropertyName="Text" Type="int32" />
</FilterParameters>
</asp:SqlDataSource>
This just returns the id when I type in a number. It doesn't work for name. What can I do?
Try changing the type = "String" and convert ID to String, like CONVERT([Id],'System.String') like '{0}'

ASP Gridview Select statement not working (GUID)

I'm using ASP.net to use a gridview. The gridview's sql data source is a select statement where ID = a value (a GUID) from a querystring.
However, when I try and preview it, it doesn't show any results. If I change it to a different type (int) of 1, then it works fine and shows results.
If I do the select statement in SQL Server Management Studio (with the GUID), it works fine and shows the results.
Here's the code for the data:
<asp:SqlDataSource ID="SQLDataSourceL" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [FName], [Date] FROM [Table1] WHERE (([FName] = #FName) AND ([Type] = #Type)) ORDER BY [Date] DESC, [FName]">
<SelectParameters>
<asp:QueryStringParameter Name="FName" QueryStringField="id" Type="Object" />
<asp:Parameter DefaultValue="X" Name="Type" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
(I've changed the column names).
Hope you can help.
Try changing the QueryStringParameter to the suitable type, eg:
<asp:QueryStringParameter Name="FName" QueryStringField="id" Type="String" />

How to filter using a dropdown in a gridview and display all values when none is selected

I have a web page with 3 values (1 text box, and 2 drop-downs) and displays result in a gridview. This is working great when the value that I want to search is in the drop-down. However, if the user didn't select one of the dropdownlist ( facilityCode), we would like to display all facility codes versus only one. What is the easiest way to accomplish this? Below is the code related to the sqldatasource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:HCSCRMConnectionString %>"
SelectCommand="SELECT MMM_Id_Nbr, Item_Desc, Supplier_Nbr, Supplier_Name, Stocking_Facility_Code, Reorder_Point_Qty, BodID, Active_Ind FROM BOD_ROP_TBL WHERE (MMM_Id_Nbr = #MMM_Id_Nbr)and active_Ind=#Active_Ind and Stocking_Facility_Code=#FacilityCode"
UpdateCommand="UPDATE BOD_ROP_TBL SET Reorder_Point_Qty = #Reorder_Point_Qty, Active_Ind = #Active_Ind WHERE (BodID = #BodID)">
<SelectParameters>
<asp:FormParameter FormField="txt3MID" Name="MMM_Id_Nbr" Type="String" />
<asp:FormParameter FormField="dropActive" Name="Active_Ind" Type="String" />
<asp:FormParameter FormField="FacilityCode" Name="FacilityCode" Type="String" />
</SelectParameters>

Resources