当前位置:编程学习 > C#/ASP.NET >>

急..gridview中的2個下拉菜單

gridview   gd1
 中有2個下拉菜單
        drop1和drop2
       (drop1和drop2是在gridview中的)

       

                              <asp:GridView ID="gd1" runat="server" AllowPaging="True" AllowSorting="True"
                        AlternatingRowStyle-BackColor="#eeeeee" AutoGenerateColumns="False" HeaderStyle-BackColor="#aaaadd"
                        HeaderStyle-Height="21" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle"
                        HeaderStyle-Wrap="false" OnRowCommand="GridView2_RowCommand"
                        Width="850px" PageSize="15" OnRowCreated="GridView2_RowCreated" OnDataBound="GridView2_DataBound">
                        <PagerSettings Visible="False" />
                        <Columns>
                           
                          
                          <asp:TemplateField HeaderText="班級">                           
                             <HeaderStyle Wrap="False" /> 
                               <ItemTemplate> 
                                     <asp:DropDownList id="drop1"  runat="server" >
                                     </asp:DropDownList>  
                               </ItemTemplate>
                            </asp:TemplateField> 
                            <asp:TemplateField HeaderText="學生">                           
                             <HeaderStyle Wrap="False" /> 
                               <ItemTemplate> 
                                     <asp:DropDownList id="drop2"  runat="server">
                                     </asp:DropDownList>  
                               </ItemTemplate>
                            </asp:TemplateField> 
                                                        
                        </Columns>                      
                        <RowStyle BorderStyle="None" Font-Size="10pt" Height="21px" Wrap="False" />
                        <HeaderStyle BackColor="#AAAADD" Font-Size="10pt" Height="21px" HorizontalAlign="Center"
                            VerticalAlign="Middle" Wrap="False" />
                        <AlternatingRowStyle BackColor="#EEEEEE" />
                    </asp:GridView>
       

        
       drop1綁定的班級﹐drop2綁定的學生
要求是﹐當drop1的values改變﹐drop2的綁定值也改變﹐也就是聯動
        比如 drop1綁定了a,b,c,d,e,f(班級)
           drop2綁定了所有學生s1,s2,s3,s4,s5,s6...s100
           如果drop1選中了b班級﹐那么drop2的值就只能有s20,s21,s22...s40就是b班學生

這個怎么弄? --------------------编程问答-------------------- 各位幫忙看看呢 --------------------编程问答-------------------- 根据Drop1的选项去查询填充Drop2 --------------------编程问答-------------------- 后台邦定,都可以实现 --------------------编程问答-------------------- 在 GridView 的事件中findControl  得到DropDownList1的selectValue,用这去查询后绑顶到DropDownList2 --------------------编程问答-------------------- 根据Drop1的值去数据库查询数据填充Drop2的值, 很容易的 --------------------编程问答-------------------- 啊﹐是那么做﹐可是我取drop1得selectvalue怎么會出錯呢? --------------------编程问答--------------------
引用 6 楼 lixue57mei 的回复:
啊﹐是那么做﹐可是我取drop1得selectvalue怎么會出錯呢?


看看你的代码 --------------------编程问答-------------------- 你不贴你的代码我们怎么知道你错在哪里呢? --------------------编程问答-------------------- 在 GridView 的事件中findControl  得到DropDownList1的selectValue,用这去查询后绑顶到DropDownList2 --------------------编程问答--------------------
引用 9 楼 zengxie 的回复:
在 GridView 的事件中findControl  得到DropDownList1的selectValue,用这去查询后绑顶到DropDownList2

首先事件要选对,第二能够找到你要的控件,第三,才是联动;lz出错一般就是前两个环节把 --------------------编程问答-------------------- 再解決這個問題之前﹐額外問你們一個問題
怎么讀取 每一行 drop1的選中值 --------------------编程问答-------------------- 用findControl找到dropdownlist,获取dropdownlist的selectvalue值,可读取dropdownlist中的值啊  --------------------编程问答-------------------- 把代码贴出来看一下吧 --------------------编程问答--------------------

  #region "GridView2_RowCreated()"
    protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
    {
        object ob = e.Row.FindControl("drop1");
        DropDownList ddlunit1 = (DropDownList)ob;        
        if (ddlunit1 != null)
        {

            this.DataDownList_DataBind(ddlunit1, "select u_funcid,u_funcname from km_func", true);
        }        
        object ob1 = e.Row.FindControl("drop2");
        DropDownList ddlunit2 = (DropDownList)ob1;
        if (ddlunit2 != null)
        {

            this.DataDownList_DataBind(ddlunit2, "select u_levelid,u_levelid from km_level where u_funcid='"+ ddlunit1.SelectedValue +"' ", true);
        }
    }
    #endregion

意思如上面的代易做图﹐drop2的綁定弄不上去
讀不到drop1每行的selectvalue
而且drop1的選中事件改變﹐怎么讓drop2的綁定值也改變

select u_levelid,u_levelid from km_level where u_funcid='"+ ddlunit1.SelectedValue +"'
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,