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"
Related
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" />
<AlternatingRowStyle BackColor="#F7F7F7" HorizontalAlign="Justify" Wrap="False" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ButtonType="Image" />
<asp:CommandField ShowEditButton ="True" ButtonType="Image" />
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Occupation" SortExpression="Occupation">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Occupation") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Occupation") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Role" SortExpression="Role">
<EditItemTemplate>
<asp:DropdownList ID="Roles" runat="server" Text='<%# Bind("Roles") %>'>
<asp:ListItem Selected="True" Text="User" value="User"></asp:ListItem>
<asp:ListItem Selected="False" Text="Admin" value="Admin"></asp:ListItem>
</asp:DropdownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Roles") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="Mobile">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Mobile") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Mobile") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle HorizontalAlign="Center" Wrap="False" />
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:UsTravelConnectionString %>"
DeleteCommand="DELETE FROM [Users] WHERE [Id] = #Id"
InsertCommand="INSERT INTO [Users] ([Name], [Email], [Occupation],[Roles], [Address], [Mobile]) VALUES (#Name, #Email, #Occupation,#Roles, #Address, #Mobile)"
SelectCommand="SELECT [Name], [Email], [Occupation],[Roles], [Address], [Mobile], [Id] FROM [Users]"
UpdateCommand="UPDATE [Users] SET [Name] = #Name, [Email] = #Email, [Occupation] = #Occupation, [Roles]=#Roles, [Address] = #Address, [Mobile] = #Mobile WHERE [Id] = #Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Occupation" Type="String" />
<asp:Parameter Name="Roles" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Mobile" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Occupation" Type="String" />
<asp:Parameter Name="Roles" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Mobile" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<p runat="server" id="noRowsMsg" sytle="display:none"></p>
</form>
Email field has unique key constraint in tables. I am getting difficulty in handling the exception and outputting an user friendly message that informs to update a new EmailID while updating email.
one possible way is to introduce validation between the "Insert Click" and the actual DB insert action.
you can do this by adding an Inserting event handler to the Sql Data Source.
OnInserting="SqlDataSource_Inserting"
Once you have done that, define the handler as:
protected void SqlDataSource_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
var emailToBeInserter = e.Command.Parameters["#Email"].Value;
// do a DB lookup call and validate if it is unique.
// if not unique, cancel the Insert and display an error message.
e.Cancel = true; // if email already exists in DB.
// if unique, do nothing.
}
Doing explicit validation has the cost of additional DB calls, but is normally a better alternative than letting the "INSERT" logic run through and throw "Unique key" and other such exceptions.
I created an web application and include a GridView that will retrieve records from a table testtable.
The code is as follows:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="product_no" HeaderText="product_no"
InsertVisible="False" ReadOnly="True" SortExpression="product_no" />
<asp:BoundField DataField="product_name" HeaderText="product_name"
SortExpression="product_name" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
<asp:BoundField DataField="expire_date" HeaderText="expire_date"
SortExpression="expire_date" />
<asp:BoundField DataField="expire_time" HeaderText="expire_time"
SortExpression="expire_time" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testbaseConnectionString %>"
DeleteCommand="DELETE FROM testtable WHERE (product_no = #product_no)"
InsertCommand="INSERT INTO testtable(product_name, price, expire_date, expire_time) VALUES (#product_name, #price, #expire_date, #expire_time)"
SelectCommand="SELECT testtable.* FROM testtable"
UpdateCommand="UPDATE testtable SET product_name = #product_name, price = #price, expire_date = #expire_date, expire_time = #expire_time WHERE (product_no = #product_no)">
<DeleteParameters>
<asp:Parameter Name="product_no" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="product_name" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="product_name" />
<asp:Parameter Name="price" />
<asp:Parameter Name="expire_date" />
<asp:Parameter Name="expire_time" />
<asp:Parameter Name="product_no" />
</UpdateParameters>
</asp:SqlDataSource>
But when I click the Edit link of a specific records of the GridView and make some changes, then I click the Update link but the changes is not reflected and it seems that it does not update into the table. (The Edit link look exactly like the one show in the following picture)
What could I be missing?
Checkout these links hope it helps you
Insert , Update, Delete using SQLDataSource
on Asp.net Blogs
There is no "DataKeyNames" in the GridView control.
Modify your gridView tag as follow:
<asp:GridView DataKeyNames="product_no" ... />
try changing these two
<asp:BoundField DataField="product_no" HeaderText="product_no"
InsertVisible="False" ReadOnly="True" SortExpression="product_no" />
<asp:BoundField DataField="product_name" HeaderText="product_name"
SortExpression="product_name" />
with this
<asp:TemplateField HeaderText="product_name" SortExpression="product_name">
<ItemTemplate>
<asp:HiddenField id="hfProduct_No" runat="server" value='<%# Bind("product_no") %>' />
<asp:Label id="lblProduct_name" runat="server" Text ='<%#Bind("product_name")%>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField id="hfProduct_No" runat="server" value='<%# Bind("product_no") %>' />
<asp:TextBox id="txtProduct_name" runat="server" Text ='<%#Bind("product_name")%>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
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!