How to display drop down list item based on value from other column in gridview during editing.
My gridview have many column and are editable. User can edit data that was displayed in the gridview by click the "Edit" button.
In EditItemTemplate, i have put a few drop down list.
For example:
1) PhaseDropDownList
Item: - Definition Phase
- Confirmation Phase
2) StatusDropDownList
Item: - User Requirement
- Preliminary Review
- Technical Review
- Cost Model
- Final Review
My problem is; in edit mode, when user click the definition phase from the PhaseDropDownList in Phase column, item in StatusDropDownList in Status column will only display: User Requirement, Preliminary Review
and when user click the confirmation phase from the PhaseDropDownList in Phase column, item in StatusDropDownList in Status column will only display: Technical Review, Cost Model, Final Review.
I don't know how to do this please help me to solve my problem.
Here is my code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="id" DataSourceID="SqlDataSource1"
GridLines="Horizontal">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
<asp:BoundField DataField="description" HeaderText="DESCRIPTION"
SortExpression="description" />
<asp:TemplateField HeaderText="COMPANY NAME" SortExpression="company_name">
<EditItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("company_name") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("company_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MONTH NAME" SortExpression="month_name">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="month_name"
DataValueField="month_name" SelectedValue='<%# Bind("month_name") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("month_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="rev" HeaderText="REV" SortExpression="rev" />
<asp:BoundField DataField="COGS" HeaderText="COGS" SortExpression="COGS" />
<asp:BoundField DataField="GP" HeaderText="GP" SortExpression="GP" />
<asp:BoundField DataField="pGP" HeaderText="%GP" SortExpression="pGP" />
<asp:BoundField DataField="rev_OM" HeaderText="O&M REV"
SortExpression="rev_OM" />
<asp:BoundField DataField="COGS_OM" HeaderText="O&M COGS"
SortExpression="COGS_OM" />
<asp:BoundField DataField="GP_OM" HeaderText="O&M GP"
SortExpression="GP_OM" />
<asp:BoundField DataField="pGP_OM" HeaderText="O&M %GP"
SortExpression="pGP_OM" />
<asp:TemplateField HeaderText="CATEGORY" SortExpression="category_proposal">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource3" DataTextField="category_proposal"
DataValueField="category_proposal"
SelectedValue='<%# Bind("category_proposal") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("category_proposal") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PHASE" SortExpression="phase_proposal">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource4" DataTextField="phase_proposal"
DataValueField="phase_proposal" SelectedValue='<%# Bind("phase_proposal") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("phase_proposal") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="STATUS" SortExpression="status_proposal">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server"
DataSourceID="SqlDataSource5" DataTextField="status_proposal"
DataValueField="status_proposal" SelectedValue='<%# Bind("status_proposal") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("status_proposal") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TYPE" SortExpression="type_proposal">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="SqlDataSource6" DataTextField="type_proposal"
DataValueField="type_proposal" SelectedValue='<%# Bind("type_proposal") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("type_proposal") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BDE" SortExpression="BDE">
<EditItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("BDE") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("BDE") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="START DATE" SortExpression="start_date">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("start_date", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("start_date", "{0:MM/dd/yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="END DATE" SortExpression="end_date">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("end_date", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("end_date", "{0:MM/dd/yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DURATION" SortExpression="duration">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("duration") %>'></asp:TextBox>
<asp:DropDownList ID="DropDownList6" runat="server"
DataSourceID="SqlDataSource7" DataTextField="duration"
DataValueField="duration" SelectedValue='<%# Bind("duration_type") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("duration") %>'></asp:Label>
<asp:Label ID="Label14" runat="server" Text='<%# Bind("duration_type") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="duration_type" HeaderText="duration_type"
SortExpression="duration_type" Visible="False" />
<asp:TemplateField HeaderText="VENDOR" SortExpression="vendor">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList7" runat="server"
DataSourceID="SqlDataSource8" DataTextField="vendor_name"
DataValueField="vendor_name" SelectedValue='<%# Bind("vendor") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("vendor") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="remarks" HeaderText="REMARKS"
SortExpression="remarks" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
ReadOnly="True" SortExpression="id" Visible="False" />
</Columns>
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
DeleteCommand="DELETE FROM [Proposal_listing] WHERE [id] = @id"
InsertCommand="INSERT INTO [Proposal_listing] ([description], [company_name], [month_name], [rev], [COGS], [GP], [pGP], [rev_OM], [COGS_OM], [GP_OM], [pGP_OM], [category_proposal], [phase_proposal], [status_proposal], [type_proposal], [BDE], [start_date], [end_date], [duration], [duration_type], [vendor], [remarks]) VALUES (@description, @company_name, @month_name, @rev, @COGS, @GP, @pGP, @rev_OM, @COGS_OM, @GP_OM, @pGP_OM, @category_proposal, @phase_proposal, @status_proposal, @type_proposal, @BDE, @start_date, @end_date, @duration, @duration_type, @vendor, @remarks)"
SelectCommand="SELECT * FROM [Proposal_listing]"
UpdateCommand="UPDATE [Proposal_listing] SET [description] = @description, [company_name] = @company_name, [month_name] = @month_name, [rev] = @rev, [COGS] = @COGS, [GP] = @GP, [pGP] = @pGP, [rev_OM] = @rev_OM, [COGS_OM] = @COGS_OM, [GP_OM] = @GP_OM, [pGP_OM] = @pGP_OM, [category_proposal] = @category_proposal, [phase_proposal] = @phase_proposal, [status_proposal] = @status_proposal, [type_proposal] = @type_proposal, [BDE] = @BDE, [start_date] = @start_date, [end_date] = @end_date, [duration] = @duration, [duration_type] = @duration_type, [vendor] = @vendor, [remarks] = @remarks WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="company_name" Type="String" />
<asp:Parameter Name="month_name" Type="String" />
<asp:Parameter Name="rev" Type="Decimal" />
<asp:Parameter Name="COGS" Type="Decimal" />
<asp:Parameter Name="GP" Type="Decimal" />
<asp:Parameter Name="pGP" Type="Decimal" />
<asp:Parameter Name="rev_OM" Type="Decimal" />
<asp:Parameter Name="COGS_OM" Type="Decimal" />
<asp:Parameter Name="GP_OM" Type="Decimal" />
<asp:Parameter Name="pGP_OM" Type="Decimal" />
<asp:Parameter Name="category_proposal" Type="String" />
<asp:Parameter Name="phase_proposal" Type="String" />
<asp:Parameter Name="status_proposal" Type="String" />
<asp:Parameter Name="type_proposal" Type="String" />
<asp:Parameter Name="BDE" Type="String" />
<asp:Parameter Name="start_date" Type="DateTime" />
<asp:Parameter Name="end_date" Type="DateTime" />
<asp:Parameter Name="duration" Type="String" />
<asp:Parameter Name="duration_type" Type="String" />
<asp:Parameter Name="vendor" Type="String" />
<asp:Parameter Name="remarks" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="company_name" Type="String" />
<asp:Parameter Name="month_name" Type="String" />
<asp:Parameter Name="rev" Type="Decimal" />
<asp:Parameter Name="COGS" Type="Decimal" />
<asp:Parameter Name="GP" Type="Decimal" />
<asp:Parameter Name="pGP" Type="Decimal" />
<asp:Parameter Name="rev_OM" Type="Decimal" />
<asp:Parameter Name="COGS_OM" Type="Decimal" />
<asp:Parameter Name="GP_OM" Type="Decimal" />
<asp:Parameter Name="pGP_OM" Type="Decimal" />
<asp:Parameter Name="category_proposal" Type="String" />
<asp:Parameter Name="phase_proposal" Type="String" />
<asp:Parameter Name="status_proposal" Type="String" />
<asp:Parameter Name="type_proposal" Type="String" />
<asp:Parameter Name="BDE" Type="String" />
<asp:Parameter Name="start_date" Type="DateTime" />
<asp:Parameter Name="end_date" Type="DateTime" />
<asp:Parameter Name="duration" Type="String" />
<asp:Parameter Name="duration_type" Type="String" />
<asp:Parameter Name="vendor" Type="String" />
<asp:Parameter Name="remarks" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [month_name] FROM [Month]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [category_proposal] FROM [Proposal_category]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [phase_proposal] FROM [proposal_phase]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [status_proposal] FROM [Proposal_status]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [type_proposal] FROM [Proposal_Type]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource7" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [duration] FROM [duration]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource8" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [vendor_name] FROM [Vendor]"></asp:SqlDataSource>