在网格视图的行数据绑定事件中下拉列表选择的索引错误 [英] Drop down list selected index error in row data bound event of grid view

查看:48
本文介绍了在网格视图的行数据绑定事件中下拉列表选择的索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我遇到了一个问题,即我的ddl在gv的编辑模式下不能按要求工作.假设我在gv中有一个用户信息,并且它在标签中显示已启用".然后,我单击gv的编辑按钮,并使用ddl使用户启用或禁用.默认情况下,即使用户被禁用,它也会选择启用的字段或选定的索引. gv的更新工作正常.那里没有其他错误,只有ddl显示错误的数据.我的代码在下面是gvn:

Hi,

I am suffering through a problem that my ddl is in not working as req in edit mode of gv. Suppose if i have a user info in gv and it shows Enabled as in label. Then i click on edit button of gv and ddl is taken to make the user enabled or disabled. By default is is picking the enabled field or selected index even if the user is disabled. Updation of gv is working fine. No other error is there, only the ddl is showing incorrect data. My Code is gvn below:

protected void gv_All_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow &&
          (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
        {
            string strEnabled = Convert.ToString(Session["enabled"]);
            DropDownList ddlenabled = (DropDownList)e.Row.FindControl("ddlEnabled");
            if (strEnabled!= "")
            {
                if (strEnabled== "Disabled")
                {
                    ddlenabled.SelectedIndex=2;
                }
                else
                {

                    ddlenabled.SelectedIndex = 1;
                }
            }
            else
            {
                ddlenabled.SelectedIndex = 0;
            }
        }
    }



请原谅我的简短表格...我非常着急...
请尽快提供帮助...:(



and please forgive me for my short forms... I am in extreme hurry...
Please help ASAP...:(

推荐答案



正如我在您的代码中看到的那样,您正在尝试操纵字符串"strEnabled"的值,其中存储了Session ["enabled"]. "strEnabled"的值从不更改ddl selectedindexchanged的值.

因此,我建议您对strEnabled字符串值进行计算,或在gv行中获取ddlenabled控件的值.

如果仍然有任何查询,请还原.

快乐编码:)
Hi,

as I can see in your code, you are trying to manipulate the value of a string "strEnabled" which stores Session["enabled"]. The value of "strEnabled" never changes on ddl selectedindexchanged.

Hence I would suggest you to work out on strEnabled strings value, or fetch the value of control ddlenabled in gv row.

Revert if you still have any queries.

Happy Coding :)


这篇关于在网格视图的行数据绑定事件中下拉列表选择的索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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