Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何基于Gridview本身上存在的下拉选择显示Gridview数据?_C#_Sql_Asp.net_.net_Visual Studio - Fatal编程技术网

C# 如何基于Gridview本身上存在的下拉选择显示Gridview数据?

C# 如何基于Gridview本身上存在的下拉选择显示Gridview数据?,c#,sql,asp.net,.net,visual-studio,C#,Sql,Asp.net,.net,Visual Studio,我有类似的数据 计划选项值 计划1选项1 10 计划1选项2 20 计划2选项1 50 计划2选项2 70 计划399 我想要一个GridView来分组类似的计划,并有一个显示选项的下拉列表。选择一个选项将在第三列中显示不同的值 计划|带有[option1]和[option2]的下拉菜单|由下拉选择驱动的值 最好的方法是什么 我希望我是清楚的。 谢谢 您的aspx文件 <asp:GridView ID="GridView1" AutoGenerateColumns="false" run

我有类似的数据

计划选项值
计划1选项1 10
计划1选项2 20
计划2选项1 50
计划2选项2 70
计划399

我想要一个GridView来分组类似的计划,并有一个显示选项的下拉列表。选择一个选项将在第三列中显示不同的值

计划|带有[option1]和[option2]的下拉菜单|由下拉选择驱动的值

最好的方法是什么

我希望我是清楚的。 谢谢

您的aspx文件

<asp:GridView ID="GridView1"  AutoGenerateColumns="false" runat="server">
    <Columns>
        <asp:BoundField DataField="Plan" HeaderText="PLAN" />
        <asp:TemplateField HeaderText="OPTION">                    
            <ItemTemplate>
                <asp:DropDownList ID="DropDownList1" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" runat="server">
                    <asp:ListItem Value="-1">select</asp:ListItem>
                    <asp:ListItem Value="1">Option1</asp:ListItem>
                    <asp:ListItem Value="2">Option2</asp:ListItem>
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText ="VALUE">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </ItemTemplate>
             </asp:TemplateField>
    </Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack) CreateTable();        
}
public void CreateTable()
{
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("Plan", typeof(string)));
    dt.Rows.Add("Plan1");
    dt.Rows.Add("Plan1");
    dt.Rows.Add("Plan2");
    dt.Rows.Add("Plan2");
    dt.Rows.Add("Plan3");
    GridView1.DataSource = dt;
    GridView1.DataBind();

} 
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList drp1 = (DropDownList)sender;
    Label lbl = new Label();
    GridViewRow grow = (GridViewRow)(drp1).Parent.Parent;
    lbl = (Label)grow.FindControl("Label1");
    lbl.Text = "bind  " + drp1.SelectedItem.Text + "  value here";      
}