We help IT Professionals succeed at work.
Get Started

EditItemTemplate - Dropdownlist

innocent1973 asked
Last Modified: 2012-05-09
Hello Experts,
I have an editItemTemplate column with a dropdownlist. I would like to add items based on the gridview's selected column.
Is there any way to do this?

My code is like below:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        AutoGenerateEditButton="True" BackColor="White" BorderColor="#3366CC" 
        BorderStyle="None" BorderWidth="1px" CellPadding="4" 
        <RowStyle BackColor="White" ForeColor="#003399" />
            <asp:TemplateField HeaderText="Class">
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("sSinifKodu") %>'></asp:Label>
            <asp:TemplateField HeaderText="Size Type">
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSource1" DataTextField="sBedenTipi" 
                        DataValueField="sBedenTipi" Height="25px" Width="126px">
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:FOREVERConnectionString2 %>" 
                        SelectCommand="SELECT sBedenTipi FROM IAS_ClassSizeTypes WHERE (sSinifKodu = @sSinifKodu)">
                            <asp:ControlParameter ControlID="GridView1" Name="sSinifKodu" 
                                PropertyName="SelectedRow.Columns[1].ToString()" Type="String" />
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("sBedenTipi") %>'></asp:Label>
            <asp:TemplateField HeaderText="Assortmen Type"></asp:TemplateField>
        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:FOREVERConnectionString %>" 
        SelectCommand="SELECT sSinifKodu, sBedenTipi FROM IAS_ClassSizeTypes">

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE