繁体   English   中英

如何在C#中单击按钮时在gridview中获取下拉值?

[英]how to get dropdown value inside gridview on button click in c#?

我已经尝试过了,但是它不起作用,给出了空值:请告诉我此代码中必须更改的内容。

      protected void Button1_Click(object sender, EventArgs e)
 {
 GridViewRow row;
row = dgData.Rows[0];
DropDownList ddl= (DropDownList)(row.Cells[1].FindControl("ddlCol1"));

}

采用

DropDownList ddl =(DropDownList)(row.FindControl(“ ddlCol1”));

试着让我知道

在点击事件上尝试此代码

foreach (GridViewRow row in GridView1.Rows)
    {
        //Finding Dropdown control  
        DropDownList ddl1 = row.FindControl("ddlTest") as DropDownList;
        if (ddl1 != null)
        {
           // your code here  
        }
    }

@creby我看到了您的代码。

您将在行数据绑定事件确定期间在网格视图中添加下拉菜单。.但是,当您单击按钮时,所有下拉菜单都将消失,因此这就是您无法下拉菜单的原因。

使用网格视图的项目模板,然后在行数据绑定事件中绑定下拉列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM