在网格视图中查找下拉菜单的选定项目值 [英] Finding selected items value of drop down inside grid view

查看:53
本文介绍了在网格视图中查找下拉菜单的选定项目值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个网格视图.内部网格视图中我已经接受了模板字段,并且在其中放置了下拉列表.我在行数据绑定事件上填充了下拉列表.现在我的问题是我想在选定索引更改上选择项目值list.so的下拉列表,所以当我从下拉列表中选择任何项目时如何获取其选定的值.



网格视图中填充下拉菜单的编码

Hello All,
I have a grid view.Inside grid view i have taken template field and i have put drop down list in it.I am filling drop down list on row data bound event.Now my problem is that i want select items value on selected index change of drop down list.so when i select any item from drop down list how to get its selected value.



coding of filling drop down inside grid view

 DataRowView r = e.Row.DataItem as DataRowView;
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                   
                        DropDownList drptype1;
                        drptype1 = (DropDownList)(e.Row.FindControl("drpitem"));
                        DataSet fill = objitem.get_all_details();
                        drptype1.DataSource = fill.Tables[0];
                        drptype1.DataTextField = "item_name";
                        drptype1.DataValueField = "item_id";
                        drptype1.DataBind();
                        drptype1.Items.Insert(0, new ListItem("Select", "-1"));
}


那么如何获取其选择的值


so how to get its selected value

推荐答案

drptype1.SelectedItem.Value返回是什么
what is drptype1.SelectedItem.Value returning


我假设您想要一个事件处理程序当用户在GridView内的DropDownList 中选择一个值时,将在CodeBehind中执行该方法.为此,我有以下建议:

后行

I assume you want an event handler method to be executed in the CodeBehind when user selects a value in the DropDownList inside the GridView. To do this, I have the following suggestions:

After the line

DropDownList drptype1;
drptype1 = (DropDownList)(e.Row.FindControl("drpitem"));



添加以下代码行,以将SelectedIndexChanged 事件处理程序添加到DropDownList:



Add the following line of code to add a SelectedIndexChanged event handler to the DropDownList:

drptype1.SelectedIndexChanged += new EventHandler(DropDownList_SelectedIndexChanged);



并且,如下所示在CodeBehind中定义EventHandler DropDownList_SelectedIndexChanged:



And, define the EventHandler DropDownList_SelectedIndexChanged in the CodeBehind as follows:

void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
        DropDownList ddl = sender as DropDownList;
        if (ddl != null)
        {
            string selectedValue = ddl.SelectedItem.Value;
            string selectedText = ddl.SelectedItem.Text;
        }
}


这篇关于在网格视图中查找下拉菜单的选定项目值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆