I am attempting to use DetailsView in ASP.NET and c# to show a list of students that are associated with the logged-in user (which will be a teacher after they login to the system). I have been trying to using scalar values so my program can be more dynamic once a teacher types in the last name of the student they want to find in the system. I'm not sure why I am getting the error
must declare the scalar value
when I (think I) am declaring it on the ASP side of my code. I've been searching for solutions to this for a couple of hours now so any and all help would be greatly appreciated.
ASP.NET Code:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblUserBlank" runat="server" Text="joeB" ></asp:Label>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btSearch" runat="server" OnClick="btSearch_Click" Text="Search" />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="LastName"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="StudentID" HeaderText="StudentID" ReadOnly="True" SortExpression="StudentID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:BoundField DataField="TShirt_Size" HeaderText="TShirt_Size" SortExpression="TShirt_Size" />
</Fields>
<EmptyDataTemplate>
No Student found
</EmptyDataTemplate>
</asp:DetailsView>
<asp:SqlDataSource
runat="server"
ID="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:Lab3 %>"
SelectCommand="SELECT Student.StudentID, Student.LastName, Student.FirstName, Student.Age, Student.TShirt_Size FROM Student INNER JOIN Teacher ON Student.TeacherID = Teacher.TeacherID WHERE Teacher.Username = #Username AND Student.LastName = #LastName">
<SelectParameters>
<asp:ControlParameter ControlID="txtSearch" Name="#LastName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="lblUserBlank" Name="#Username" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Content>
c# code behind:
protected void btSearch_Click(object sender, EventArgs e)
{
DetailsView1.DataBind();
}
Change this line:
<asp:ControlParameter ControlID="txtSearch" Name="#LastName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="lblUserBlank" Name="#Username" PropertyName="Text" Type="String" />
for this (remove the # char from the Name flag value):
<asp:ControlParameter ControlID="txtSearch" Name="LastName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="lblUserBlank" Name="Username" PropertyName="Text" Type="String" />
Related
I'm having the classic "EditItemTemplate"/"Cannot find Control" error, because I have search parameters that refer to a ControlID inside an EditItemTemplate inside a GridView. I've tried prepending my ControlID with the ID of the GridView (gridview$controlID), but it isn't working. I'm happy to resort to using "code-behind" methods if I have to, but I'd much rather understand why the prepending method isn't working. Any tips based on the code below?
Thanks!
<asp:UpdatePanel ID="upMatchEntry" ChildrenAsTriggers="false" EnableViewState="false" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlGameWeek" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gvMatchSelect" DataKeyNames="MatchID,HomeTeamID,AwayTeamID"
DataSourceID="sdsMatches" runat="server" AutoGenerateEditButton="True"
AutoGenerateColumns="False" EmptyDataText="No Matches Found" ContentPlaceHolderID="cpMatchSelect">
<Columns>
<asp:TemplateField HeaderText="Home Team" SortExpression="HomeTeamName" ItemStyle-HorizontalAlign="left">
<ItemTemplate><%# Eval("HomeTeamName") %></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlHomeTeam" DataSourceID="sdsHomeTeams"
DataTextField="HomeTeamName" DataValueField="HomeTeamID"
SelectedValue='<%# Bind("HomeTeamID") %>' AutoPostBack="True" />
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Away Team" SortExpression="AwayTeamName" ItemStyle-HorizontalAlign="left">
<ItemTemplate><%# Eval("AwayTeamName") %></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlAwayTeam" DataSourceID="sdsAwayTeams"
DataTextField="AwayTeamName" DataValueField="AwayTeamID"
SelectedValue='<%# Bind("AwayTeamID") %>' AutoPostBack="True"/>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sdsMatches" ConnectionString='<%$ ConnectionStrings:ApplicationServices %>' runat="server"
SelectCommand="pGameWeekMatchAdminDisplay" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Name="GameWeekID" ControlID="ddlGameWeek" PropertyName="SelectedValue" Type="Int32" DefaultValue="-1" />
<asp:ControlParameter Name="DivisionID" ControlID="ddlDivision" PropertyName="SelectedValue" Type="Int32" DefaultValue="-1" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsHomeTeams" ConnectionString='<%$ ConnectionStrings:ApplicationServices %>' runat="server"
SelectCommand="SELECT 'Select Home Team' AS HomeTeamName, -1 AS HomeTeamID UNION SELECT Name AS HomeTeamName, TeamID AS HomeTeamID FROM Team WHERE DivisionID = #DivisionID AND TeamID <> #AwayTeamID" >
<SelectParameters>
<asp:ControlParameter Name="DivisionID" ControlID="ddlDivision" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter Name="AwayTeamID" ControlID="gvMatchSelect$ddlAwayTeam" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsAwayTeams" ConnectionString='<%$ ConnectionStrings:ApplicationServices %>' runat="server"
SelectCommand="SELECT 'Select Away Team' AS AwayTeamName, -1 AS AwayTeamID UNION SELECT Name AS AwayTeamName, TeamID AS AwayTeamID FROM Team WHERE DivisionID = #DivisionID AND TeamID <> #HomeTeamID" >
<SelectParameters>
<asp:ControlParameter Name="DivisionID" ControlID="ddlDivision" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter Name="HomeTeamID" ControlID="gvMatchSelect$ddlHomeTeam" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
The controls are nested inside of a GridViewRow which implements the INamingContainer interface. If you're using a recent version of ASP.NET and only need single-row editing, you should be able to work around this by making the control ID static:
ClientIDMode="Static"
Hello I have a bit of ASP.Net Code below. I am trying to figure out how to make my submit button:
<asp:Button ID="makepost" runat="server" Text="Post My Tip/Story"
ValidationGroup="createpost" />
work properly. When I try to add AccessDataSource1.Insert() I get an error saying this:
CS1061: 'ASP.main_aspx' does not contain a definition for
'AccessDataSource1' and no extension method 'AccessDataSource1'
accepting a first argument of type 'ASP.main_aspx' could be found (are
you missing a using directive or an assembly reference?)
What do I need to type to make this work? All of my code is below.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF">
<p style="font-size: 20px">Welcome Back!<br />
Begin Sharing and Reading Space Tips Below!
</p>
<p> Current Posts:
<asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataKeyNames="ID">
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:BoundField DataField="User" HeaderText="User" SortExpression="User" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Timeof" HeaderText="Timeof"
SortExpression="Timeof" />
<asp:BoundField DataField="Post" HeaderText="Post" SortExpression="Post" />
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Posts.mdb"
SelectCommand="SELECT * FROM [UserPost] ORDER BY [Timeof]"
DeleteCommand="DELETE FROM [UserPost] WHERE [ID] = ?"
InsertCommand="INSERT INTO [UserPost] ([ID], [User], [Title], [Timeof], [Post]) VALUES (?, ?, ?, ?, ?)"
UpdateCommand="UPDATE [UserPost] SET [User] = ?, [Title] = ?, [Timeof] = ?, [Post] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="User" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Timeof" Type="DateTime" />
<asp:Parameter Name="Post" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter Name="ID" Type="Int32" ControlID="TextBox5" PropertyName="Text" />
<asp:ControlParameter Name="User" Type="String" ControlID="TextBox1" PropertyName="Text" />
<asp:ControlParameter Name="Title" Type="String" ControlID="TextBox2" PropertyName="Text" />
<asp:ControlParameter Name="Timeof" Type="DateTime" ControlID="TextBox3" PropertyName="Text" ConvertEmptyStringToNull="true"/>
<asp:ControlParameter Name="Post" Type="String" ControlID="TextBox4" PropertyName="Text" />
</InsertParameters>
</asp:AccessDataSource>
</p>
<table><tr><td> <asp:Label ID="Label5" runat="server" Text="ID: "></asp:Label></td><td>
<asp:TextBox ID="TextBox5" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
<tr><td> <asp:Label ID="Label1" runat="server" Text="User: "></asp:Label></td><td>
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
<tr><td><asp:Label ID="Label2" runat="server" Text="Title: "></asp:Label></td><td><asp:TextBox ID="TextBox2"
runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
<tr><td><asp:Label ID="Label3" runat="server" Text="Date: "></asp:Label></td><td> <asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox></td></tr>
<tr><td valign="top"><asp:Label ID="Label4" runat="server" Text="Story: "></asp:Label></td><td valign="top">
<asp:TextBox ID="TextBox4" runat="server" Height="129px" Width="474px" TextMode="MultiLine"></asp:TextBox></td></tr>
</table>
<asp:Button ID="makepost" runat="server" Text="Post My Tip/Story"
ValidationGroup="createpost" /><br />
</div>
</LoggedInTemplate><AnonymousTemplate>
<asp:Login ID="Login1" runat="server" ForeColor="White">
</asp:Login><br /><div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#FFFFFF">Please Register to be begin viewing and sharing your
<br />Star Wars Old Republic Tips and Stories!</div>
</AnonymousTemplate>
</asp:LoginView>
</asp:Content>
Your AccessDataSource is inside LoginView, you have to find the control:
Dim AccessDataSource1 As AccessDataSource = DirectCast(LoginView1.FindControl("AccessDataSource1"), AccessDataSource)
Regards.
in C# it would be this then
AccessDataSource AccessDataSource1 = (AccessDataSource)LoginView1.FindControl("AccessDataSource1");
'ASP.main_aspx' does not contain a definition for 'AccessDataSource1'
I think that your AccessDataSource control is located in the wrong place: you've put it in the LoginView. The error message says that the runtime can't find the control in the root of your page. So, try to put the AccessDataSource outside the LoginView.
This line. Take a look at:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
Do you see AccessDataSource1? Are you perhaps pointing to the incorrect Datasource? Or, did you name it differently and not realize it?
I'm aware that this question has been asked before. I have looked through them in hopes to find a reason I'm having issues.
I keep getting this error whenever I try to delete a user from a table within my form. I can edit them, I just can't delete them. I have done research to try and figure it out with no luck.
html code:
<div align="center">
<asp:Label ID="Label1" runat="server" Text="Manage Users"></asp:Label>
<p>
<asp:Label ID="Label2" runat="server" Text="User Name:"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label3" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label4" runat="server" Text="Security Level:"></asp:Label>
<asp:DropDownList ID="drpdwnlstSecurityLevel" runat="server"
onselectedindexchanged="drpdwnlstSecurityLevel_SelectedIndexChanged">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>U</asp:ListItem>
</asp:DropDownList>
</p>
<p>
<asp:Button ID="btnAddUser" runat="server" onclick="btnAddUser_Click1"
Text="Add User" />
</p>
<p>
<asp:Label ID="lblError" runat="server"></asp:Label>
</p>
</div>
<p>
</p>
<div align="center">
<asp:GridView ID="tblUserLogin" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" InsertVisible="False"
SortExpression="UserID"></asp:BoundField>
<asp:BoundField DataField="UserName" HeaderText="UserName"
SortExpression="UserName"></asp:BoundField>
<asp:BoundField DataField="UserPassword" HeaderText="UserPassword"
SortExpression="UserPassword"></asp:BoundField>
<asp:BoundField DataField="SecurityLevel" HeaderText="SecurityLevel"
SortExpression="SecurityLevel"></asp:BoundField>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
<asp:CommandField ShowDeleteButton="True"></asp:CommandField>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/PayrollSystem_DB.mdb"
SelectCommand="SELECT [UserID], [UserName], [UserPassword], [SecurityLevel] FROM [tblUserLogin]"
DeleteCommand="DELETE FROM [tblUserLogin] WHERE [UserID] = ?"
InsertCommand="INSERT INTO [tblUserLogin] ([UserID], [UserName], [UserPassword], [SecurityLevel]) VALUES (?, ?, ?, ?)"
UpdateCommand="UPDATE [tblUserLogin] SET [UserName] = ?, [UserPassword] = ?, [SecurityLevel] = ? WHERE [UserID] = ?">
<DeleteParameters>
<asp:Parameter Name="UserID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="UserPassword" Type="String" />
<asp:Parameter Name="SecurityLevel" Type="String" />
<asp:Parameter Name="UserID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="UserID" Type="Int32" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="UserPassword" Type="String" />
<asp:Parameter Name="SecurityLevel" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</form>
</body>
You need to set the DataKeyNames property of the gridview:
datakeynames="UserID"
According to the MSDN documentation:
"You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work. The values of these key fields are passed to the data source control in order to specify the row to update or delete."
So i have a gridview that is set up using an object datasource(web service) to display a table. The table currently comes up, and at the end of the table has an edit option. what i would like to do is when a user clicks the edit option, The row comes up with a dropdown box with available options obtained from a webservice. As of right now the table loads correctly, and comes up with the data from the object datasource. The problem is however, when you click on the edit button, What comes up in the columns that contain a dropbox, and inside of the dropbox, is the pathway for the datasource being linked to the combobox. What is suppose to be there is the Textvalue of that source's object, and when selected the item use's that selected items unique id all obtained from the datasource. Below you will find what i have tried so far:
<asp:GridView ID="GridViewHolder"
runat="server"
AutoGenerateColumns="False"
BorderColor="Black"
BorderStyle="Ridge"
BorderWidth="2px"
DataSourceID="MachineDataSet"
ForeColor="DarkBlue"
HeaderStyle-HorizontalAlign="Center"
HorizontalAlign="Center"
RowStyle-HorizontalAlign="Center" >
<RowStyle HorizontalAlign="Center" />
<Columns>
<asp:BoundField DataField="SiteName"
HeaderText="Site Name"
SortExpression="SiteName" />
<asp:BoundField DataField="Name"
HeaderText="Machine Name"
SortExpression="Name" />
<asp:TemplateField HeaderText="Machine Type"
SortExpression="MachineType">
<EditItemTemplate>
<telerik:RadComboBox ID="Machine_Type"
runat="server"
EmptyMessage="Select a Machine Type."
EnableLoadOnDemand="true"
DataSourceID="GetMachineType"
EnableVirtualScrolling="true">
</telerik:RadComboBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("MachineType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Machine Model" SortExpression="MachineModel">
<EditItemTemplate>
<telerik:RadComboBox ID="Machine_Model"
runat="server"
EmptyMessage="Select a Machine Model."
EnableLoadOnDemand="true"
DataSourceID="GetMachineModel"
EnableVirtualScrolling="true">
</telerik:RadComboBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("MachineModel") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
</Columns>
<HeaderStyle HorizontalAlign="Center" />
</asp:GridView>
This is the grid i am currently using.
<asp:ObjectDataSource ID="MachineDataSet"
runat="server"
SelectMethod="GetMachineSiteDetails"
TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
<SelectParameters>
<asp:Parameter DefaultValue=""
Name="siteid"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="GetMachineType"
runat="server"
SelectMethod="GetMachineTypeList"
TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
<SelectParameters>
<asp:Parameter Name="siteid" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="GetMachineModel"
runat="server"
SelectMethod="GetMachineModelList"
TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
<SelectParameters>
<asp:Parameter Name="siteid" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
These are the object datasources i am currently using.
Now my problem comes up in the edittemplates, And what i believe to be the issue is that the dropbox is in fact getting the correct data, but it has no way to display it properly.
What i would like to know is how can i get it so that when you click edit, the dropbox will come up in the editable columns of the grid and when they are clicked to display available options it comes up with the selectable items, and not this for each option in the datasource:
Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService
Any help or suggestions are greatly appreciated.
Thank you.
Okay after mucking around a bit with this i think i figured out the right setup for this using just a regular asp:dropdownlist.
This is now the code i used in my .ascx page:
<asp:GridView ID="GridViewHolder"
runat="server"
AutoGenerateColumns="False"
BorderColor="Black"
BorderStyle="Ridge"
BorderWidth="2px"
DataSourceID="MachineDataSet"
ForeColor="DarkBlue"
HeaderStyle-HorizontalAlign="Center"
HorizontalAlign="Center"
RowStyle-HorizontalAlign="Center"
AllowPaging="True">
<RowStyle HorizontalAlign="Center" />
<Columns>
<asp:BoundField DataField="SiteName"
HeaderText="SiteName"
SortExpression="SiteName"
ReadOnly="True" />
<asp:BoundField DataField="Name"
HeaderText="Machine Name"
SortExpression="Name"
ReadOnly="True" />
<asp:TemplateField HeaderText="Machine Type"
SortExpression="MachineType">
<EditItemTemplate>
<asp:ObjectDataSource ID="GetMachineType"
runat="server"
SelectMethod="GetMachineTypeList"
TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService"
UpdateMethod="UpdateMachineTypes">
<UpdateParameters>
<asp:Parameter Name="machineId" Type="Int32" />
<asp:Parameter Name="machineType" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="siteid" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="Machine_Type"
runat="server"
DataSourceID="GetMachineType"
DataTextField="Name"
DataValueField="ID"
Height="17px"
Width="181px">
<asp:ListItem Selected="True"
Text="Select a Machine Type.">
</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("MachineType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Machine Model" SortExpression="MachineModel">
<EditItemTemplate>
<asp:ObjectDataSource ID="GetMachineModel"
runat="server"
SelectMethod="GetMachineModelList"
TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService"
UpdateMethod="UpdateMachineModels">
<UpdateParameters>
<asp:Parameter Name="machineId" Type="Int32" />
<asp:Parameter Name="machineModel" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="siteid" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="Machine_Model"
runat="server"
DataSourceID="GetMachineModel"
DataTextField="Name"
DataValueField="ID"
Width="181px"
Height="17px">
<asp:ListItem Selected="True"
Text="Select a Machine Model.">
</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("MachineModel") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowHeader="True" />
</Columns>
<HeaderStyle HorizontalAlign="Center" />
</asp:GridView>
<asp:ObjectDataSource ID="MachineDataSet"
runat="server"
SelectMethod="GetMachineSiteDetails"
TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
<SelectParameters>
<asp:Parameter DefaultValue=""
Name="siteid"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
If you find anything wrong or have a comment about this design, feel free to comment for i am still pretty new to working with asp.net and any suggestions are a great help!
I am having problem with the following code. Delete function does not work (throws scalar variable error). Update function does not work ... it does not throw any error, but it simply does not make changes to the database.
If I make exact DetailsView, everything works OK. Where is the problem?
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ServisnaKnjiga.aspx.cs" Inherits="CernaticJurij_Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<p>
Registrska številka:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Iskanje" />
</p>
<p>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" Height="50px" Width="915px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="REG_STEVILKA" HeaderText="REGISTRSKA ŠTEVILKA"
SortExpression="REG_STEVILKA" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="VIN_STEVILKA" HeaderText="VIN ŠTEVILKA"
SortExpression="VIN_STEVILKA" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="ZNAMKA" HeaderText="ZNAMKA"
SortExpression="ZNAMKA" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="MODEL" HeaderText="MODEL" SortExpression="MODEL"
InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="LETO_IZDELAVE" HeaderText="LETO IZDELAVE"
SortExpression="LETO_IZDELAVE" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="ID_ZAPISA" HeaderText="ID_ZAPISA"
InsertVisible="False" ReadOnly="True" SortExpression="ID_ZAPISA" />
<asp:BoundField DataField="DATUM" HeaderText="DATUM"
SortExpression="DATUM" />
<asp:BoundField DataField="KILOMETRINA" HeaderText="KILOMETRINA"
SortExpression="KILOMETRINA" />
<asp:BoundField DataField="OPIS" HeaderText="OPIS" SortExpression="OPIS" />
<asp:BoundField DataField="ODG_OSEBA" HeaderText="ODGOVORNA OSEBA"
SortExpression="ODG_OSEBA" />
<asp:BoundField DataField="CENA" HeaderText="CENA" SortExpression="CENA" />
<asp:BoundField DataField="REG_STEVILKA1" HeaderText="REG_STEVILKA1"
SortExpression="REG_STEVILKA1" Visible="False" />
<asp:BoundField DataField="ID_STRANKE" HeaderText="ID_STRANKE"
SortExpression="ID_STRANKE" Visible="False" />
<asp:BoundField DataField="PROSTORNINA_MOTORJA" HeaderText="PROSTORNINA_MOTORJA"
SortExpression="PROSTORNINA_MOTORJA" Visible="False" />
<asp:BoundField DataField="MOC_MOTORJA"
HeaderText="MOC_MOTORJA" SortExpression="MOC_MOTORJA"
Visible="False" />
<asp:BoundField DataField="TIP_MOTORJA" HeaderText="TIP_MOTORJA"
SortExpression="TIP_MOTORJA" Visible="False" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
</p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Stranke %>"
DeleteCommand="DELETE FROM [SERVISNI_ZAPIS] WHERE [ID_ZAPISA] = #ID_ZAPISA"
InsertCommand="INSERT INTO [SERVISNI_ZAPIS] ([REG_STEVILKA], [DATUM], [KILOMETRINA], [OPIS], [ODG_OSEBA], [CENA]) VALUES (#REG_STEVILKA, #DATUM, #KILOMETRINA, #OPIS, #ODG_OSEBA, #CENA)" SelectCommand="SELECT *
FROM SERVISNI_ZAPIS
FULL JOIN VOZILO
ON (SERVISNI_ZAPIS.REG_STEVILKA=VOZILO.REG_STEVILKA)
WHERE (SERVISNI_ZAPIS.REG_STEVILKA = #REG_STEVILKA)"
UpdateCommand="UPDATE [SERVISNI_ZAPIS] SET [REG_STEVILKA] = #REG_STEVILKA, [DATUM] = #DATUM, [KILOMETRINA] = #KILOMETRINA, [OPIS] = #OPIS, [ODG_OSEBA] = #ODG_OSEBA, [CENA] = #CENA WHERE [ID_ZAPISA] = #ID_ZAPISA">
<DeleteParameters>
<asp:Parameter Name="ID_ZAPISA" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:ControlParameter ControlID="TextBox1" Name="REG_STEVILKA"
PropertyName="Text" />
<asp:Parameter DbType="Date" Name="DATUM" />
<asp:Parameter Name="KILOMETRINA" Type="String" />
<asp:Parameter Name="OPIS" Type="String" />
<asp:Parameter Name="ODG_OSEBA" Type="String" />
<asp:Parameter Name="CENA" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="REG_STEVILKA"
PropertyName="Text" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
<asp:Parameter DbType="Date" Name="DATUM" />
<asp:Parameter Name="KILOMETRINA" Type="String" />
<asp:Parameter Name="OPIS" Type="String" />
<asp:Parameter Name="ODG_OSEBA" Type="String" />
<asp:Parameter Name="CENA" Type="String" />
<asp:Parameter Name="ID_ZAPISA" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</p>
<p>
</p>
<p>
</p>
</asp:Content>
Do you mean it doesn't work with a gridview but does work with a DetailsView? If so, then you need to set DataKeyNames for the gridview.
You can look at this for further details: http://fabdata.wordpress.com/2007/03/23/must-declare-the-scalar-variable-id/
I solved it by adding:
<asp:DetailsView ID="DetailsView1" runat="server" DataKeyNames="ID"....