I have a GridView. It's connected to a SqlDataSource. My database is Oracle.
When I run the webpage, SELECT command works and I see the items in the list. When I click Delete button, I get this error:
ORA-01036: illegal variable name/number
Here is my GridView and SqlDataSource:
<telerik:RadAjaxPanel ID="ajaxMyLinks" runat="server" width="100%" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadGrid ID="gridMyLinks" runat="server" DataSourceID="SqlDataSourceMyLinks" AllowAutomaticDeletes="True" AllowPaging="True" BackColor="White" BorderColor="White" PageSize="5" ShowHeader="False">
<MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSourceMyLinks" DataKeyNames="N_USER_LINK_ID">
<Columns>
<telerik:GridHyperLinkColumn AllowSorting="False" DataNavigateUrlFields="V_LINK" DataNavigateUrlFormatString="{0}" DataTextField="V_LINK_TITLE" DataTextFormatString="{0}" FilterControlAltText="Filter column column" UniqueName="column" Target="_blank">
</telerik:GridHyperLinkColumn>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ImageUrl="Content/images/delete.png" UniqueName="column1">
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
<PagerStyle Mode="NextPrev" ShowPagerText="False" />
</telerik:RadGrid>
</telerik:RadAjaxPanel>
<asp:SqlDataSource ID="SqlDataSourceMyLinks" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT V_LINK_TITLE, V_LINK, N_USER_LINK_ID FROM TAPP_IFH_USER_LINK WHERE (N_USER_ID = :USER_ID) ORDER BY N_USER_LINK_ID DESC" DeleteCommand="DELETE FROM TAPP_IFH_USER_LINK WHERE (N_USER_LINK_ID = :USER_LINK_ID)" ProviderName="<%$ ConnectionStrings:DefaultConnection.ProviderName %>">
<DeleteParameters>
<asp:Parameter Name="USER_LINK_ID" Type="Int32"></asp:Parameter>
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter Name="USER_ID" SessionField="USER_ID" />
</SelectParameters>
</asp:SqlDataSource>
Found the solution. Parameter names were not matching between column name in DB and parameter. Parameter name was USER_LINK_ID while column name was N_USER_LINK_ID.
If this is not the problem in your case, check this post out. It has more suggestions
Related
I have a Gridview which uses a dropdown list to provide a value applied to a SQL query which filters to the applicable data. The issue is that when an item is selected from the list the gridview does not update, the DefaultValue remains as the filter.
I've tried a number of alternatives seen though StackOverflow like by directly binding the value in the markup but to no success yet.
<label for="City" class="control-label">Filter by City:</label>
<div>
<asp:DropDownList ID="CityDropdown" runat="server" Width="123px" >
<asp:ListItem>Aberdeen</asp:ListItem>
<asp:ListItem>Armagh</asp:ListItem>
<asp:ListItem>Bangor</asp:ListItem>
<asp:ListItem>Bath</asp:ListItem>
</asp:DropDownList>
</div>
</div>
<hr />
<asp:Panel ID="PanelFoodbanks" runat="server">
<asp:GridView ID="ListFoodbanks" runat="server" AutoGenerateColumns="False" AllowSorting="True" DataSourceID="SqlDataSource_FindCity" EmptyDataText="There are no data records to display." CssClass="table table-responsive" GridLines="None">
<Columns>
<asp:BoundField DataField="Id" SortExpression="Id" ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden">
<HeaderStyle CssClass="hidden" />
<ItemStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="Other Field" HeaderText="OF" SortExpression="Other Field" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource_FindFoodbanks" runat="server" ConnectionString="<%$ ConnectionStrings:dbcon %>" SelectCommand="SELECT * FROM [Table] WHERE ([City] = #CityDropdown)">
<SelectParameters>
<asp:Parameter Name="CityDropdown" DefaultValue="Aberdeen"/>
</SelectParameters>
</asp:SqlDataSource>
Preferably the gridview just update dynamically when a different value in the dropdown is selected, rather than having the need to press another button etc.
Thanks in advance for any help or pointers.
I believe you need to use ControlParameter bound to city dropdown list control in your SQL Datasource:
<asp:SqlDataSource ID="SqlDataSource_FindFoodbanks" runat="server" ConnectionString="<%$ ConnectionStrings:dbcon %>" SelectCommand="SELECT * FROM [Table] WHERE ([City] = #CityDropdown)">
<SelectParameters>
<asp:ControlParameter ControlID="CityDropdown" Name="CityDropdown"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
Also add AutoPostBack="true" ondropdown list
<asp:DropDownList ID="CityDropdown" AutoPostBack="true" runat="server" Width="123px" >
Note: I noticed that in your code GridView is using DataSourceID SqlDataSource_FindCity and not SqlDataSource_FindFoodbanks
Sorry I cannot upload the screenshot due to the limited number of my reputation since I am a newbie here.
ora_aspnet_user table with column name userid with datatype of Raw(16)
link to
Instruct Table with userid with datatype of Raw (16) - Other columns is ID (Auto Trigger No), Command (Varchar2 = 256)
MY INLINE ASPX CODE:
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" Visible="False" />
<asp:BoundField DataField="COMMAND" HeaderText="COMMAND" SortExpression="COMMAND" />
<asp:TemplateField HeaderText="USERID">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="USERNAME" DataValueField="USERID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
InsertCommand="INSERT INTO INSTRUCT (COMMAND, USERID) VALUES (:COMMAND, :USERID)">
<InsertParameters>
<asp:Parameter Name="COMMAND" Type="String" />
<asp:Parameter Name="USERID" DbType="Binary" Size="16" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT USERID, USERNAME FROM ORA_ASPNET_USERS">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
The above code will only insert the command textbox and but will not insert the USERID from the USERID dropdown.
I would really appreciate your help.
Thank you very much.
Replace your datasource <InsertParameter> with this one, it might help you, because I don't have your source code I cannot test it locally, the problem could occur somewhere elese though:
<InsertParameters>
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="USERID" Type="Byte"></asp:ControlParameter>
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedItem.Text" Name="COMMAND" Type="String"></asp:ControlParameter>
</InsertParameters>
I need to make a delete statement for results that are displayed in my GridView. This delete statement must use some of the columns themselves as parameters in the delete statement
My gridview is this:
<asp:GridView
ID="GridView1"
runat="server"
AllowPaging="True"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
style="z-index: 1; left: 222px; top: 139px; position: absolute; height: 299px; width: 458px" DataKeyNames="Id">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="Column1" HeaderText="Column1" SortExpression="Column1" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="department" HeaderText="department" SortExpression="department" />
<asp:BoundField DataField="courseCode" HeaderText="courseCode" SortExpression="courseCode" />
<asp:BoundField DataField="courseName" HeaderText="courseName" SortExpression="courseName" />
</Columns>
</asp:GridView>
I need to use "Column1" and "Id" from my SELECT query (That is stored within a stored procedure) for the DELETE query that is ran when the "Delete" button is hit on my Gridview. A problem that may be happening is my select statement uses one primary key, but my delete statement needs two primary keys (which are "Column1" and "Id"), so I do not know what to set DataKeyNames to.
Here is the SQLDataSource:
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="GetPreviouslyTakenCourses"
SelectCommandType="StoredProcedure"
DeleteCommand="DELETE FROM UserHasCourse WHERE UserHasCourse.userId=#Column1 AND UserHasCourse.courseId=#Id"
DeleteCommandType="Text">
<SelectParameters>
<asp:SessionParameter DefaultValue="1" Name="userId" SessionField="userId" Size="10" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Column1" Type="Int32" />
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
As of now nothing happens when I hit "Delete" on the GridView, so I can imagine the problem I am having is almost fixed. I can imagine there is a problem with <asp:Parameter but I don't know what.
DataKeyNames should be set to
DataKeyNames="Column1,Id"
And this problem is fixed
I have 3 gridviews
1st gridview enable selection, which will populate the 2nd gridview if it has any data.
while the 3rd gridview is nested inside the 2nd gridview.
However, the 3rd gridview never ever show any single data..
What am i missing?
I can achieve this if the 2nd gridview is populated on the page load.
here is the code
im on asp.net c#
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="SurveyID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="SurveyID" HeaderText="SurveyID"
SortExpression="SurveyID" />
<asp:BoundField DataField="SurveyTitle" HeaderText="SurveyTitle"
SortExpression="SurveyTitle" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT [SurveyID], [SurveyTitle] FROM [Survey]">
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="QuestionID" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="QuestionID" HeaderText="QuestionID"
InsertVisible="False" ReadOnly="True" SortExpression="QuestionID" />
<asp:BoundField DataField="QuestionTitle" HeaderText="QuestionTitle"
SortExpression="QuestionTitle" />
<asp:BoundField DataField="AnswerType" HeaderText="AnswerType"
SortExpression="AnswerType" />
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" DataKeyNames="ResultID">
<Columns>
<asp:BoundField DataField="ResultID" HeaderText="ResultID"
SortExpression="ResultID" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="QuestionID" HeaderText="QuestionID"
SortExpression="QuestionID" />
<asp:BoundField DataField="AnswerValue" HeaderText="AnswerValue"
SortExpression="AnswerValue" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT * FROM [Results] WHERE ([QuestionID] = #QuestionID)">
<SelectParameters>
<asp:Parameter Name="QuestionID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT [QuestionID], [QuestionTitle], [AnswerType] FROM [Question] WHERE ([SurveyID] = #SurveyID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="SurveyID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You have to set AutoPostBack="True" on GridView1, so that it posts back if the user selected a row. But I'm not familiar with SqlDataSource. So i would set GridView2's DataSource property in the SelectedIndexChanged handler and then DataBind it.
If you want to bind the data to the inner's grid when GridView2 is bound, you should handle the RowDataBound event of GridView2, find the inner grid there, set it's datasource and databind it.
void GridView2_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var rowView = (DataRowView)e.Row.DataItem;
var GridView3 = (GridView)e.Row.FindControl("GridView3");
//set it's DataSource according to this row's DataItem
}
}
I have a gridview which I am binding through code behind, I want to filter the gridview based on the value given by the user in textbox.
It would be great if I'll be able to filter the gridview without any postback.
PLease help!
Thanks in advance
you could run a filter expression
<asp:sqldatasource id="articles" runat="server"
connectionstring="<%$ ConnectionStrings:aspa %>"
selectcommand="SELECT title, url, added, updated FROM aspx_articles ORDER BY title"
filterexpression="title LIKE '%{0}%' or url LIKE '%{0}%'">
<filterparameters>
<asp:controlparameter controlid="searchBox" propertyname="Text" />
</filterparameters>
</asp:sqldatasource>
or this way
Do you have a TextBox outside the GridView, and when you enter data into it and press a button, the GirdView should be filter on that data?
If so, make sure your select command can taka a parameter with the value you want to filter on. Add a ControlParameter to the SelectParameters colelction of the DataSource control (if you use a DataSource control).
Here is an example that uses the Northwind database, maybe this will help you:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ShowFooter="True">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitsInStock], [UnitPrice] FROM [Alphabetical list of products] WHERE ([ProductName] LIKE '%' + #ProductName + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DefaultValue="%" Name="ProductName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
codes found here http://forums.asp.net/p/1034014/2904713.aspx
If you're using paging, I would recommend using something else (like the Microsoft Ajax Library's dataView). Because gridview paging and client-side filtering wouldn't mesh too well. But if you're not doing paging, you could do something similar to this or this.
The grid view is made for manipulation during post back. If you were to do this entirely on the client side, you'd use a JavaScript suite that would work on any table, not confined to the grid view. If it were me, I would simply use AJAX by wrapping the grid view and text box in an Update Panel. To the end user, the behavior is the same.
EDIT to include Sample code:
<asp:ScriptManager ID="ScriptManager1" AllowCustomErrorsRedirect="false" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="txtFilterString" ></asp:TextBox>
<asp:Button runat="server" ID="btnFilter" Text="FilterResults" onclick="btnFilter_Click" />
<asp:GridView runat="server" ID="grdResults"
DataKeyNames="Id"
AllowSorting="true" AllowPaging="true" PageSize="20"
PagerSettings-Mode="NumericFirstLast">
<Columns>
.....
</Columns>
</asp:GridView>
</asp:UpdatePanel>