Issue with MS AJAX reorder list. ASP.NET - asp.net

am using a reorder list in my UI. My reorder list is and SQLDataSource are shown below. I get an error message
"Reorder failed, see details below.\r\n\r\nFailed to reorder."
Seems trivial but not able to find the issue. Can you please help me with this issue ?
SOURCE CODE
' />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>'
SelectCommand="SELECT * FROM TBL_BATCH_STAGE WHERE RQUST_KEY=#RequestId ORDER BY [ORDER_NO] ASC"
UpdateCommand="UPDATE [TBL_BATCH_STAGE] SET [ORDER]=#Order WHERE [BATCH_STG_KEY] = #original_ID"
OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:SessionParameter Name="RequestId" SessionField="RequestId" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Order" Type="Int32" />
<asp:Parameter Name="original_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>

Resolved this issue.My SQL parameters did not match my ReorderList variable names.
<asp:SqlDataSource ID="SqlDataSource1" OldValuesParameterFormatString="original_{0}" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>'
SelectCommand="SELECT * FROM TBL_BATCH_STAGE WHERE RQUST_KEY=#RequestId ORDER BY [ORDER_NO] ASC"
UpdateCommand="UPDATE [TBL_BATCH_STAGE] SET [ORDER_NO]=#ORDER_NO WHERE [BATCH_STG_KEY] = #original_BATCH_STG_KEY" >
<SelectParameters>
<asp:SessionParameter Name="RequestId" SessionField="RequestId" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ORDER_NO" Type="Int32" />
<asp:Parameter Name="original_BATCH_STG_KEY" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:ReorderList ID="ReorderList1" runat="server" AllowReorder="true" DataKeyField="BATCH_STG_KEY" DataSourceID="SqlDataSource1" SortOrderField="ORDER_NO">
<ItemTemplate>
<table style="border:solid 1px #cccccc;">
<tr>
<td style="vertical-align:top;list-style:none;font-size:13px;padding:0 0 0 0;">
<asp:Label ID="ItemLabel" runat="server" Text='<%# Eval("BATCH_STG_TEXT")%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:ReorderList>

Related

Input string was not in a correct format vb.net/asp.net

Here's my formview..
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="recid">
<EditItemTemplate>
RECID:
<asp:TextBox ID="recid" runat="server" Text='<%# Eval("RECID") %>' ReadOnly="true" />
<br />
SHIPPER:
<asp:TextBox ID="shipper" runat="server" Text='<%# Bind("SHIPPER") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:FormView>
here's my sqldatasource1
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM IMPORT WHERE (RECID = ?)"
UpdateCommand="UPDATE IMPORT SET SHIPPER=#shipper WHERE RECID=#recid" >
<SelectParameters>
<asp:ControlParameter ControlID="Label1" Name="RECID" PropertyName="Text" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="recid" Type="Int32" />
<asp:Parameter Name="shipper" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Now, my problem is that everytime I update the page, this is the error Input string was not in a correct format.
I tried changing the #recid in the UpdateCommand into a constant UpdateCommand="UPDATE IMPORT SET SHIPPER=#shipper WHERE RECID=11186" this worked well, the update was successful.
I think the #recid is being treated as a string here in the UpdateCommand. Can someone please help me? What do I need to do in order to change the data type of #recid to Integer?
Thanks!
First thing you need to fix is to bind raceid with the textbox like below:
<asp:TextBox ID="recid" runat="server" Text='<%# Bind("RECID") %>' ReadOnly="true" />
Now there's a question about provider. In select command you have used RACEID = ?, ? is used for OleDb or Odbc. If you are using any of them, you have to change Update Command to this:
UpdateCommand="UPDATE IMPORT SET SHIPPER=? WHERE RECID=?"
And UpdateParameters to this (Notice their order):
<UpdateParameters>
<asp:Parameter Name="shipper" Type="String" />
<asp:Parameter Name="recid" Type="Int32" />
</UpdateParameters>
I would recommend reading this MSDN article: Using Parameters with the SqlDataSource Control

Autogenerated Gridview with All Cells in Edit Mode by Default

So I've got a gridview bound to a SQL datasource stored procedure. The stored procedure returns a pivot table, where a number of columns are unknown until run time. I therefore need to autogenerate the columns.
The gridview is intended to allow Excel-like data updates. So the goal is to have the grid load as textboxes. I know if I were to declare the columns on my aspx page, I could create template columns and handle their visibility that way.
So I believe I need a way to programmatically set all the columns to template fields (without knowing the column names), or I need to discover the method by which I can just "flip the switch" and just make everything editable.
Thanks in advance!
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSourceExcelGridTest">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceExcelGridTest" runat="server" ConnectionString="<%$ ConnectionStrings:WebAppsConnectionString %>" SelectCommand="spJobForecastingGetEmployeesByDepartmentAndProject_v1" SelectCommandType="StoredProcedure" UpdateCommand="spJobForecastingUpdateHours" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="DepartmentNumber" Type="String" DefaultValue="13211" />
<asp:Parameter Name="ProjectNumber" Type="String" DefaultValue="13211" />
<asp:Parameter Name="startDate" Type="DateTime" DefaultValue="2/21/2014" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="DepartmentNumber" Type="String" />
<asp:Parameter Name="ProjectNumber" Type="String" />
<asp:Parameter Name="Alias" Type="String" />
<asp:Parameter Name="WorkWeek" Type="DateTime" />
<asp:Parameter Name="WorkHours" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
try this:
UPDATED CODE
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSourceExcelGridTest">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceExcelGridTest" runat="server" ConnectionString="<%$ ConnectionStrings:WebAppsConnectionString %>" SelectCommand="spJobForecastingGetEmployeesByDepartmentAndProject_v1" SelectCommandType="StoredProcedure" UpdateCommand="spJobForecastingUpdateHours" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:Textbox ID="DepartmentNumber" DefaultValue="13211" text='<%# Eval("DepartmentNumber") %>'></asp:TextBox>
<asp:Textbox ID="ProjectNumber" Type="String" DefaultValue="13211" Text='<%# Eval("ProjectNumber") %>'></asp:TextBox>
<asp:Textbox ID="startDate" Type="DateTime" DefaultValue="2/21/2014" Text='<%# Eval("startDate") %>'></asp:TextBox>
</SelectParameters>
<UpdateParameters>
<asp:Textbox ID="DepartmentNumber" Type="String" text='<%# Eval("DepartmentNumber") %>'></asp:TextBox>
<asp:Textbox ID="ProjectNumber" Type="String" text='<%# Eval("ProjectNumber") %>'></asp:TextBox>
<asp:Textbox ID="Alias" Type="String" text='<%# Eval("Alias") %>'></asp:TextBox>
<asp:Textbox ID="WorkWeek" Type="DateTime" text='<%# Eval("WorkWeek") %>'></asp:TextBox>
<asp:Textbox ID="WorkHours" Type="Int32" text='<%# Eval("WorkHours") %>'></asp:TextBox>
</UpdateParameters>
</asp:SqlDataSource>

Update dropDownList using SQL query

I am trying to update my dropdownlistB according to the categoryId chosen in dropdownlistA Using this code:
<asp:DropDownList ID="DropDownListA" runat="server" DataSourceID="SqlDataSourceA" DataTextField="Description" DataValueField="Description" AutoPostBack="True"></asp:DropDownList>
<asp:DropDownList ID="DropDownListB" runat="server" DataSourceID="SqlDataSourceB" DataTextField="Title" DataValueField="Title"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceA" runat="server" ConnectionString="<%$ ConnectionStrings:MainDbConnectionString1 %>" SelectCommand="SELECT [Description] FROM [BookCategory]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceB" runat="server" ConnectionString="<%$ ConnectionStrings:MainDbConnectionString1 %>" SelectCommand="SELECT [Title] FROM [BooksInfo] WHERE ([CategoryId] = #CId)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="" Name="CId" QueryStringField="SELECT [CategoryId] FROM [BookCategory]" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
I am new to using SQL and queries in ASP.NET and cant figure out what Im doing wrong, dropdownlistB stays empty. (AutoPostBack = true in dropdownlistA, so it should update?)
I think what you are looking for is the asp:ControlParameter like this
<asp:ControlParameter ControlID="DropDownListA" PropertyName="SelectedValue"
Name="EmpID" Type="Int32" DefaultValue="0" />
So the the query is based on the selection of DropDownListA.

WhereParameter is not working for dropdownlist

My Table structure
Courses
Id
Description
Subjects
Id
Description
Courses (Relation to Courses table).
My code as follows
td>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="LinqCourses"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqCourses" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description, Id)"
TableName="Courses" />
</td>
<td align="left" valign="top" class="style5" style="width: 124px">
<asp:DropDownList ID="ddlSubjects" runat="server" DataSourceID="LinqSubjects"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqSubjects" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description,Courses,Id)"
TableName="Subjects" Where="Courses == #Id" />
<WhereParameters>
asp:ControlParameter ControlID="ddlCourses" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</WherePrameters>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Description" DataValueField="Id"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT [Description],[Courses],[Id] FROM [table_name] WHERE ([Courses ] = #Courses ) ">
<SelectParameters>
<asp:Parameter Name="Courses" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
This is not a exact answer but this might help i guess
Your Where Property is wrong. Change this (==):
Where="Courses == #Id" />
To this (=):
Where="Courses = #Id" />
Source: MSDN

ASP.NET error, must declare the scalar variable "#ServerName" after second dropdownlist is select

There are 3 dropdownlists which are parent-child, after the 3rd dropdownlist is selected, the DetailsView will display result from all 3 dropdownlist selected. first is ServerName, second is Instance, then third is DatabaseName. After select first dropdownlist of servername, then new list of instance value appear on second dropdownlist. When I select anything on second dropdownlist. There a error message that say, "Must declare the scalar variable "#ServerName"". I don't understand what it mean and please help. Here a dropdownlist codes,
<ajaxToolkit:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="SuggestAppend" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="ServerName" DataValueField="ServerName" DropDownStyle="Simple" MaxLength="0" style="display: inline;">
</ajaxToolkit:ComboBox>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [ServerName] FROM [tblServer]">
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="Label11" runat="server" Text="Select Instance:"></asp:Label>
<br />
<asp:DropDownList ID="DropDownInstance" runat="server" AutoPostBack="True" DataSourceID="Instance" DataTextField="Instance" DataValueField="Instance">
</asp:DropDownList>
<asp:SqlDataSource ID="Instance" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [Instance] FROM [tblDatabase] WHERE [ServerName] = #ServerName">
<SelectParameters>
<asp:ControlParameter ControlID="ComboBox1" Name="ServerName" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="Label10" runat="server" Text="Select Database:"></asp:Label>
<br />
<asp:DropDownList ID="DropDownDatabase" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="DatabaseName" DataValueField="DatabaseName">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [DatabaseName] FROM [tblDatabase] WHERE [ServerName] = #ServerName AND [Instance] = #Instance">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownInstance" Name="Instance" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
Then I pass those dropdownlist function to DetailsView that come with SQLDataSource2,
on SelectCommand in SQLDataSource2, I wrote
SelectCommand="SELECT * FROM [tblDatabase] WHERE (([DatabaseName] = #DatabaseName) AND ([Instance] = #Instance) AND ([ServerName] = #ServerName))"
Then after that I add SelectParameter codes,
<SelectParameters>
<asp:ControlParameter ControlID="DropDownDatabase" Name="DatabaseName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownInstance" Name="Instance" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ComboBox1" Name="ServerName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
In SqlDataSource3, your query takes two parameters: #ServerName and #Instance. But in the select parameters, you only define #Instance. Yes, you defined #ServerName in the previous data source, but not in this one.
I fixed from what Jay metioned recently and there also another issue that I fix it on instance and database dropdownlist codes, where what I fix and it work fine.
<asp:Label ID="Label11" runat="server" Text="Select Instance:"></asp:Label>
<br />
<asp:DropDownList ID="DropDownInstance" runat="server" AutoPostBack="True" DataSourceID="Instance" DataTextField="Instance" DataValueField="Instance">
</asp:DropDownList>
<asp:SqlDataSource ID="Instance" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [Instance] FROM [tblDatabase] WHERE [ServerName] = #ServerName">
<SelectParameters>
<asp:ControlParameter ControlID="ComboBox1" Name="ServerName" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="Label10" runat="server" Text="Select Database:"></asp:Label>
<br />
<asp:DropDownList ID="DropDownDatabase" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="DatabaseName" DataValueField="DatabaseName">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [DatabaseName] FROM [tblDatabase] WHERE [ServerName] = #ServerName AND [Instance] = #Instance">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownInstance" Name="Instance" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="ComboBox1" Name="ServerName" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

Resources