Binding dropdownlist to dropdownlist to detailsview ASP.NET C# - c#

I'm trying to bind a Dropdownlist to a Detailsview control in a page where the result of the second Dropdownlist depends on the first one. I could bind a single Dropdownlist to a Detailsview but if I add another Dropdownlist where the result depends on the first one the details view wont show anything unless you refresh the page.
So is there any way I could post the result of the detailsview automatically if the second dropdown is selected? I'm currently studying this but I couldnt get it.
Here's my sample code
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="LibrarySystem.Member.Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h3>
Search</h3>
<p>
Choose a category
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="categoryDataSource" DataTextField="name"
DataValueField="categoryid">
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT categoryid, name FROM dbo.TblCategory">
</asp:SqlDataSource>
</p>
<p>
Choose a title
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
DataSourceID="bookDataSource" DataTextField="booktitle" DataValueField="bookid">
</asp:DropDownList>
<asp:SqlDataSource ID="bookDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [booktitle], [bookid] FROM [TblBooks] WHERE ([categoryid] = #categoryid)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="categoryid"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<p>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="bookid" DataSourceID="bookdetailsDataSource"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="bookid" HeaderText="ID/ISBN" ReadOnly="True"
SortExpression="bookid" />
<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" />
<asp:BoundField DataField="lastname" HeaderText="Author"
SortExpression="lastname" />
<asp:BoundField DataField="firstname" HeaderText=""
SortExpression="firstname" />
<asp:BoundField DataField="description" HeaderText="Description"
SortExpression="description" />
<asp:BoundField DataField="name" HeaderText="Category" SortExpression="name" />
<asp:BoundField DataField="dateadded" HeaderText="Date added"
SortExpression="dateadded" />
<asp:BoundField DataField="quantity" HeaderText="No. of copies"
SortExpression="quantity" />
<asp:BoundField DataField="EmployeeID" HeaderText="Reserved by"
SortExpression="EmployeeID" />
<asp:BoundField DataField="reservedate" HeaderText="Reserved date"
SortExpression="reservedate" />
<asp:BoundField DataField="statusname" HeaderText="Status"
SortExpression="statusname" />
</Fields>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
Any help would be much appreciated ;)
Thanks in advance

You have to put your Dependent dropdown datasource in the parent template field. it will be look like...
<asp:TemplateField HeaderText="Category">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="categoryDataSource"
DataTextField="name" DataValueField="categoryid">
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT categoryid, name FROM dbo.TblCategory"></asp:SqlDataSource>
<asp:SqlDataSource ID="bookDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [booktitle], [bookid] FROM [TblBooks] WHERE ([categoryid] = #categoryid)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="categoryid" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="bookDataSource"
DataTextField="booktitle" DataValueField="bookid">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>

Related

How do I use the information from a record in a gridview to open up more details about that record in a new page in C# ASP.NET?

I have a GridView table which links to my tblAssets table within SQL Server. I have a "View" hyperlink field which will link to the new page with the AssetID (PK) in the URL. I am wanting to use whichever AssetID is generated in the URL in a SQL View that I have created - I got close whereby clicking on the "View" field will redirect to the page and have the correct URL but will return everything from the SQL View. So I tried to change the SelectCommand but it returned an error.
This is my .aspx code for the GridView:
<form id="frmAssets" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>"
SelectCommand="SELECT * FROM [tblAssets]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="AssetID" DataSourceID="SqlDataSource1" AllowSorting="True" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
Font-Names="Segoe UI" ForeColor="Black" GridLines="Horizontal" style="font-weight: 700" AllowPaging="True" PageSize="20" Font-Size="Small">
<AlternatingRowStyle BorderStyle="None" Font-Overline="False" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="AssetID" DataNavigateUrlFormatString="AssetDetails.aspx?AssetID={0}" Text="View" />
<asp:BoundField DataField="Asset_Tag" HeaderText="Asset Tag" SortExpression="Asset_Tag" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Asset_Type" HeaderText="Asset Type" SortExpression="Asset_Type" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Serial_Number" HeaderText="Serial_Number" SortExpression="Serial_Number" >
<HeaderStyle Width="300px" />
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID" SortExpression="DepartmentID" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
</Columns>
Apologies for the poor embedding.
This is the .aspx code for the page which it redirects to (I'm assuming I need to change the SelectCommand but can't get it working:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Asset Tag" HeaderText="Asset Tag" SortExpression="Asset Tag" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>" SelectCommand="SELECT * FROM [tblAssets]"></asp:SqlDataSource>
Add SelectParameters from http get query to the detail select query
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>" SelectCommand="SELECT * FROM [tblAssets] WHERE AssetID = #AssetID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField ="AssetID" Name="AssetID" Type="Int32" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>

gridview edit template validation

when i use template in edit mode with out avalidation control ,when user click edit
lins of grid turn to edit mode and page not send eny postback to server. but when i use
edit template with validation contorol ,the page sending postback to server and page is
reloads all content agaian. how can i fix so page will act like first one
<asp:GridView ID="gridProducts" BorderColor="Black" DataSourceID="sourceProducts" DataKeyNames="ProductID" AutoGenerateColumns="false"
AllowPaging="true" PageSize="3" AllowSorting="true" EnablePersistedSelection="true" runat="server">
<HeaderStyle BackColor="Black" ForeColor="White"/>
<RowStyle BackColor="Gray" ForeColor="White" />
<Columns>
<asp:BoundField HeaderText="ID" ReadOnly="true" SortExpression="ProductID" DataField="ProductID" />
<asp:BoundField HeaderText="NAME" SortExpression="ProductName" DataField="ProductName" />
<asp:BoundField HeaderText="ONE UNIT PRICE" DataFormatString="{0:c}" SortExpression="UnitPrice" DataField="UnitPrice" />
<asp:TemplateField HeaderText="STATUS">
<ItemStyle Width="100px" />
<ItemTemplate>
<b>In Srock:</b>
<%#Eval("UnitsInStock")%><br />
<b>On Order:</b>
<%#Eval("UnitsOnOrder")%><br />
<b>Reorder</b>
<%#Eval("ReorderLevel")%>
</ItemTemplate>
<EditItemTemplate>
<b>In Stock:</b><%#Eval("UnitsInStock")%><br />
<b>On Order:</b><%#Eval("UnitsOnOrder")%><br />
<asp:TextBox ID="txtReorder" runat="server" Text='<%# Bind("ReorderLevel") %>' Width="30px"></asp:TextBox>
<asp:RangeValidator ID="rngValidator" MinimumValue="0"
MaximumValue="100" ErrorMessage="Value Out Of Range" ControlToValidate="txtReorder" EnableClientScript="true" Type="Integer" runat="server">
</asp:RangeValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="true" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sourceProducts" runat="server"
ConnectionString="<%$ConnectionStrings:Northwind%>"
SelectCommand="SELECT ProductID,ProductName,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel
FROM Products WHERE CategoryID=#CategoryID"
UpdateCommand="UPDATE Products SET ProductName=#ProductName,UnitPrice=#UnitPrice,
ReorderLevel=#ReorderLevel WHERE ProductID=#ProductID">
<SelectParameters>
<asp:ControlParameter Name="CategoryID" ControlID="gridCategories" PropertyName="SelectedDataKey.Value" />
</SelectParameters>
</asp:SqlDataSource>

updating a sql table with a datagridview using template field

so the thing is i want to limit what can the user insert when updating through a datagridview. i thought of converting that specific field into a template and make it a dropdownlist with limited options to update such field. the thing is that when i run tests with this it updates the field as null. the sqldatasource bound to the datagridview updates perfectly fine without the template field.
i was able to make this work on a table without much problem but when i tried the same thing for another table it kept giving me a null value on the dropdownlist. this latter is bound to a SqlDataSource. i checked the code on the gridview and the data source and its pretty much the same. i don't see whats the problem.
This is the code of my SqlDataSource
<asp:SqlDataSource ID="SqlCoord" runat="server"
ConnectionString="<%$ ConnectionStrings:sistema_gestion_calidadConnectionString %>"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT profesor.nombre + ' ' + profesor.apellidos AS Expr1, materia.nombre_materia, coordinadores.id_coordinador, coordinadores.id_materia, coordinadores.id_profesor FROM coordinadores INNER JOIN materia ON coordinadores.id_materia = materia.id_materia INNER JOIN profesor ON coordinadores.id_profesor = profesor.id_profesor"
UpdateCommand="UPDATE coordinadores SET id_materia = #id_materia, id_profesor = #id_profesor FROM coordinadores INNER JOIN profesor ON coordinadores.id_profesor = profesor.id_profesor INNER JOIN materia ON coordinadores.id_materia = materia.id_materia WHERE (coordinadores.id_coordinador = #original_id_coordinador)">
<UpdateParameters>
<asp:Parameter Name="id_materia" />
<asp:Parameter Name="id_profesor" />
<asp:Parameter Name="original_id_coordinador" />
</UpdateParameters>
</asp:SqlDataSource>
And this is my DataGridview
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id_coordinador"
DataSourceID="SqlCoord" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Profesor" SortExpression="Profesor">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlProfs"
DataTextField="Expr1" DataValueField="id_profesor">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlProfs" runat="server"
ConnectionString="<%$ ConnectionStrings:sistema_gestion_calidadConnectionString %>"
SelectCommand="SELECT id_profesor, nombre + ' ' + apellidos AS Expr1 FROM profesor">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Expr1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="nombre_materia" SortExpression="nombre_materia">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlMats"
DataTextField="nombre_materia" DataValueField="id_materia">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlMats" runat="server"
ConnectionString="<%$ ConnectionStrings:sistema_gestion_calidadConnectionString %>"
SelectCommand="SELECT [id_materia], [nombre_materia] FROM [materia]">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("nombre_materia") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id_coordinador" HeaderText="id_coordinador" ReadOnly="True"
SortExpression="id_coordinador" InsertVisible="False" Visible="False" />
<asp:BoundField DataField="id_materia" HeaderText="id_materia"
SortExpression="id_materia" Visible="False" />
<asp:BoundField DataField="id_profesor" HeaderText="id_profesor"
SortExpression="id_profesor" Visible="False" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>

MySql gridview delete command

I have this GridView:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete"
onclientclick="javascript:return confirm('are you sure you want to delete.');"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id"/>
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
<asp:BoundField DataField="first" HeaderText="first" SortExpression="first" />
<asp:BoundField DataField="last" HeaderText="last" SortExpression="last" />
<asp:BoundField DataField="gender" HeaderText="gender"
SortExpression="gender" />
<asp:BoundField DataField="birthday" HeaderText="birthday"
SortExpression="birthday" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
And this is the SqlDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:clientConnectionString %>"
ProviderName="<%$ ConnectionStrings:clientConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM Client;"
DeleteCommand="DELETE FROM Client WHERE id = #id AND email = #email;">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="email" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>
And when i try to excute a delete i get this error:
Parameter '#id' must be defined.
Exception Details: MySql.Data.MySqlClient.MySqlException: Parameter '#id' must be defined.
You may want to add the DataKeyNames attribute to your GridView
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. See this link
DataKeyNames="id,email"
In the context of your Gridview.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" DataKeyNames="id,email">

how to successfully populate a combobox in edit template in a gridview? asp.net

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!

Categories

Resources