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&amp;M REV" 
                                            SortExpression="rev_OM" />
                                        <asp:BoundField DataField="COGS_OM" HeaderText="O&amp;M COGS" 
                                            SortExpression="COGS_OM" />
                                        <asp:BoundField DataField="GP_OM" HeaderText="O&amp;M GP" 
                                            SortExpression="GP_OM" />
                                        <asp:BoundField DataField="pGP_OM" HeaderText="O&amp;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>
                                                &nbsp;<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>
                                                &nbsp;<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>

Recommended Answers

All 6 Replies

It's little tricky to handle the event of dropdown within grid view or listview or repeater.

I believe you need to handle the SelectedIndexChange event of your Phase_Proposal dropdown list. Then in the event you need to get the reference of your current editing row with the help of NamingContainer as dropdown doesn't support CommandName or CommandArgument. your code may look like this :

SelectedIndexChanged(object sender,EventArgs e)
{

GridiewRow gvRow = (GridViewRow)(((Control)sender).NamingContainer);

//find phase dropdown
DropDonwList drpPhaseProposal = (DropDownList)gvRow.FindControl("your phase prosal");

// find status droopdown
DropDownList drpStatus = (DropDownList)gvRow.FindControl("your status dropdown");
drpStatus.Items.Clear();
if(drpPhaseProposal.SelectedItem.Text.Equal("Definition Phase"))
{
drpStatus.Items.Add(new ListItem("your item","your value"))
}

//same way for confirmation phase.
}

Hope this will help you...Also you can refer this link for more help :

http://weblogs.asp.net/vikram/archive/2008/04/17/handling-dropdown-list-inside-gridview-with-autopostback.aspx


========================================================================================

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&amp;M REV" 
                                            SortExpression="rev_OM" />
                                        <asp:BoundField DataField="COGS_OM" HeaderText="O&amp;M COGS" 
                                            SortExpression="COGS_OM" />
                                        <asp:BoundField DataField="GP_OM" HeaderText="O&amp;M GP" 
                                            SortExpression="GP_OM" />
                                        <asp:BoundField DataField="pGP_OM" HeaderText="O&amp;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>
                                                &nbsp;<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>
                                                &nbsp;<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>

I have try to do the code as suggested. But, when i debug the program an error occur:

'string' does not contain a definition for 'Equal' and no extension method 'Equal' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

I guess that i am missing a reference at the top of my coding. But, i don't know which reference to add.Could you help me?

Oh i am sorry. It was spelling mistake. It should be Equals() not Equal()..

===========================================================================================

I have try to do the code as suggested. But, when i debug the program an error occur:

'string' does not contain a definition for 'Equal' and no extension method 'Equal' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

I guess that i am missing a reference at the top of my coding. But, i don't know which reference to add.Could you help me?

I have try the code. But when an item is selected from DropDownList3 (drop down list for phase) for example: "Definition Phase", DropDownList4 (drop down list for status) still displaying all of the status. Not only the status that is related to the value that is selected in DropDownList3. I don't know what's wrong.

Here is my code:

protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow gvRow = (GridViewRow)(((Control)sender).NamingContainer);

            //find phase dropdown
            DropDownList DropDownList3 = (DropDownList)gvRow.FindControl("DropDownList3");

            // find status dropdown
            DropDownList DropDownList4 = (DropDownList)gvRow.FindControl("DropDownList4");
            DropDownList4.Items.Clear();
            if (DropDownList3.SelectedItem.Text.Equals("Definition Phase"))
            {
                DropDownList4.Items.Add(new ListItem("User Requirement", "User Requirement"));
                DropDownList4.Items.Add(new ListItem("Preliminary Review", "Preliminary Review"));
            }

            else if (DropDownList3.SelectedItem.Text.Equals("Confirmation Phase"))
            {
                DropDownList4.Items.Add(new ListItem("Technical Review", "Technical Review"));
                DropDownList4.Items.Add(new ListItem("Cost Model", "Cost Model"));
                DropDownList4.Items.Add(new ListItem("Final Review", "Final Review"));
            }

            else if (DropDownList3.SelectedItem.Text.Equals("Delivery Phase"))
            {
                DropDownList4.Items.Add(new ListItem("Completed", "Completed"));
                DropDownList4.Items.Add(new ListItem("Approved", "Approved"));
                DropDownList4.Items.Add(new ListItem("Handovered", "Handovered"));
            }

        }

did you debug the code ? if not then please try to debug the code. put break point in SelectedIndexChange event of your phase dropdown and see whether the Items collection of your status drop down has value based on your phase selection.

Let us know the result after debugging.

========================================================================================

I have try the code. But when an item is selected from DropDownList3 (drop down list for phase) for example: "Definition Phase", DropDownList4 (drop down list for status) still displaying all of the status. Not only the status that is related to the value that is selected in DropDownList3. I don't know what's wrong.

Here is my code:

protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow gvRow = (GridViewRow)(((Control)sender).NamingContainer);

            //find phase dropdown
            DropDownList DropDownList3 = (DropDownList)gvRow.FindControl("DropDownList3");

            // find status dropdown
            DropDownList DropDownList4 = (DropDownList)gvRow.FindControl("DropDownList4");
            DropDownList4.Items.Clear();
            if (DropDownList3.SelectedItem.Text.Equals("Definition Phase"))
            {
                DropDownList4.Items.Add(new ListItem("User Requirement", "User Requirement"));
                DropDownList4.Items.Add(new ListItem("Preliminary Review", "Preliminary Review"));
            }

            else if (DropDownList3.SelectedItem.Text.Equals("Confirmation Phase"))
            {
                DropDownList4.Items.Add(new ListItem("Technical Review", "Technical Review"));
                DropDownList4.Items.Add(new ListItem("Cost Model", "Cost Model"));
                DropDownList4.Items.Add(new ListItem("Final Review", "Final Review"));
            }

            else if (DropDownList3.SelectedItem.Text.Equals("Delivery Phase"))
            {
                DropDownList4.Items.Add(new ListItem("Completed", "Completed"));
                DropDownList4.Items.Add(new ListItem("Approved", "Approved"));
                DropDownList4.Items.Add(new ListItem("Handovered", "Handovered"));
            }

        }

I forgot to set the DropDownList3 to Enable AutoPostBack. When I set it to Enable AutoPostBack and debug the code, it works as i need. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.