在Gridview复选框上的Gridveiw中启用DropDown? [英] Enable a DropDown in Gridveiw on Gridview CheckBox?

查看:63
本文介绍了在Gridview复选框上的Gridveiw中启用DropDown?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,
我试图在同一grdview中的复选框选中的事件上启用/禁用gridview行中的drowpdown.我在aspx页面中使用以下html作为




I m trying to enable/disable a drowpdown in gridview row on a checkbox checked event in the same grdview. I am using the following html in aspx page as

and

<asp:TemplateField HeaderText="DNA" HeaderStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:CheckBox ID="imgbDNA" runat="server" OnCheckedChanged="chkDNAGridview_OnCheckedChanged" />
                           </ItemTemplate>

</asp:TemplateField>


和aspx.cs代码是


and aspx.cs code is

protected void chkDNAGridview_OnCheckedChanged(object sender, EventArgs e)
       {
           CheckBox ck1 = (CheckBox)sender;
           GridViewRow grow = (GridViewRow)ck1.NamingContainer;


           foreach(GridViewRow rowitem in gvAttendance.Rows)
           {
               DropDownList ddlR = (DropDownList)rowitem.Cells[3].FindControl("ddlReason");

               if (ck1.Checked == true)
                   ddlR.Enabled = true;
               else
                   ddlR.Enabled = false;

           }



       }



该代码的问题是它在第一行的gridview中禁用/启用了下拉菜单.但是,当我选中/取消选中第二行时,它将在所有行中禁用或启用drowpdown.我只想在选中/取消选中复选框的情况下启用/禁用特定行中的下拉菜单.
在此先感谢



The problem with that code is it disable/enable dropdown in the gridview in the first row. But when i check/uncheck second row it disable or enable drowpdown in all the rows. I want to enable/disable dropdown in the specific row only on check/uncheck of checkbox.
Thanks in advance

推荐答案

但是当我选中/取消选中第二行时,它将禁用或启用所有行中的drowpdown
您的代码通过您编写的foreach循环来做到这一点!

从OnCheckChanged方法中删除foreach.改为使用,例如:
But when i check/uncheck second row it disable or enable drowpdown in all the rows
Your code is doing that via foreach loop you wrote!

Remove foreach from the OnCheckChanged method. Instead use, something like:
CheckBox ck1 = (CheckBox)sender;
GridViewRow grow = (GridViewRow)ck1.NamingContainer;
DropDownList ddlR = (DropDownList)grow.Cells[3].FindControl("ddlReason");

if (ck1.Checked == true)
    ddlR.Enabled = true;
else
    ddlR.Enabled = false;


这篇关于在Gridview复选框上的Gridveiw中启用DropDown?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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