码迷,mamicode.com
首页 > 其他好文 > 详细

GridView下DropDownList 的选择方法onselectedindexchanged 实现方法

时间:2016-12-04 17:18:58      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:val   text   send   GridView   object   dex   方法   app   view   

在GridView下面绑定好了下拉框,我们常常会遇到一个问题,

选择方法怎么实现呢,用js总是难的去算是在GridView的第几行第几个元素,因为服务器的id和客户端的id经常变化让js根本无从找起,所以我认为还是用DropnLIst的自带选择方法实现是最佳的。

下面是前端代码,要注意一点AutoPostBack一定要设为true,不然就不实现后台方法了。

 

 <asp:DropDownList ID="dddjfoot" runat="server" AppendDataBoundItems="true"

                                         AutoPostBack="true" onselectedindexchanged="dddjfoot_SelectedIndexChanged"  
                                        >
                                        <asp:ListItem Value=" ">-请选择-</asp:ListItem>
                                        <asp:ListItem Value="厂价">厂价</asp:ListItem>
                                        <asp:ListItem Value="优价">优价</asp:ListItem>
                                        <asp:ListItem Value="批发价">批发价</asp:ListItem>
                                        <asp:ListItem Value="优惠价">优惠价</asp:ListItem>
                                        <asp:ListItem Value="面议">面议</asp:ListItem>

                                    </asp:DropDownList>

 

后台代码

 

protected void dddjitem_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        GridViewRow row = (GridViewRow)ddl.Parent.Parent;
        TextBox tb = row.FindControl("txtdj") as TextBox;
        tb.Text = ddl.SelectedValue;
    }

  GridViewRow row = (GridViewRow)ddl.Parent.Parent;这句是获取当前选择行,获取这行数据基本上就能取到本行的所以值,并且能对当前行所有控件进行操作了。

 

GridView下DropDownList 的选择方法onselectedindexchanged 实现方法

标签:val   text   send   GridView   object   dex   方法   app   view   

原文地址:http://www.cnblogs.com/Jeremy2001/p/6130827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!