在gridview中插入一列TemplateField,然后在ItemTemplate中插入了2个RadioButton和DropDownList,如何让选中第2个RadioButton时,DropDownList可见。

解决方案 »

  1.   

    可以在选中第2个RadioButton时,把DropDownList.Visible=true 就可以了
      

  2.   

    初始化时把DropDownList.Visible设定为 false
      

  3.   

    关键是,如何选中RadioButton2,在TemplateField中的
      

  4.   

    DropDownList lst = GridView.Rows[m].Cells[n].FindControl("ddlSomething") as DropDownList;
      

  5.   

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       foreach(GridViewRow gvr in GridView1.Rows)
       {
          RadioButton rbtn=(RadioButton)gvr.FindControl("RadioButton2");//第二个
          if(rbtn.Checked)
          {
             DropDownList ddl=(DropDownList)gvr.FindControl("DropDownList1");
             ddl.Visible=true;
          }
       }
    }
      

  6.   

    按照zwwlovezy1的做了,但是没有反应,GridView有10个字段,第8列是2个单选按钮和下拉菜单。
    我查询了1条记录,点了RadioButton2之后没有反应。
      

  7.   

    RadioButton2的autoPostBack设置成TRUE
      

  8.   

    我试了  单选按钮根本就没有触发模板列事件
    要是在加一个模板列 里面放上按钮 然后选中RadioButton2的话  能隐藏你选的拿行的下拉列表
    上面给的代码没问题
    就是点击单选按钮没有触发模板列事件
      

  9.   

    不好意思 刚才又给你试了一下
    你模板列里不是有两个单选按钮吗 RadioButton1、RadioButton2  当点击RadioButton2的时候后面的下拉列表隐藏是吧?那你就先编辑模板  然后选中RadioButton2的 点击事件,把我上面的代码写在这里面就OK了:
        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                RadioButton rbtn = (RadioButton)gvr.FindControl("RadioButton2");//第二个
                if (rbtn.Checked)
                {
                    DropDownList ddl = (DropDownList)gvr.FindControl("DropDownList1");
                    ddl.Visible = false;
                }
            }
        }
      

  10.   

    ItemTemplate里加的,RadioButton1、RadioButton2、还有DropDownList1,RadioButton2被选中的话,DropDownList1可见。
      

  11.   

    可见你就把Visible改成true就行了贝
      

  12.   

    这个是我给你试过的 已经没有问题了:    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                RadioButton rbtn = (RadioButton)gvr.FindControl("RadioButton2");//第二个
                if (rbtn.Checked)
                {
                    DropDownList ddl = (DropDownList)gvr.FindControl("DropDownList1");
                    ddl.Visible = false;
                }
            }
        }
      

  13.   

    是不是放错事件了?
    放在模板中的那个RadioButton2的点击事件中
    因为要触发模板列事件 好象只有Button才可以 
    所以只能写在RadioButton2的点击事件里了
      

  14.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //ConfigurationSettings.AppSettings["connStr"];
            //SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["connStr"]);
            SqlConnection cn = new SqlConnection("server=.;database=jyjycy;uid=sa");
            string sqlstr = "select jkrq,bjh,zydh,fydh,js,cysj,qyg,ck,cyqk,bz from cyhw where 1=1";
            if (TextBox1.Text != "")
                sqlstr += " and bjh='" + TextBox1.Text + "'";
            else if (TextBox2.Text != "")
                sqlstr += " and zydh='" + TextBox2.Text + "'";
            else if (TextBox3.Text != "")
                sqlstr += " and fydh='" + TextBox3.Text + "'";
            else
                sqlstr = sqlstr;
            SqlCommand cmd = new SqlCommand(sqlstr,cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            
        }    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                RadioButton rbtn = (RadioButton)gvr.FindControl("RadioButton2");//第二个
                if (rbtn.Checked)
                {
                    DropDownList ddl = (DropDownList)gvr.FindControl("DropDownList1");
                    ddl.Visible = false;
                }
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
               }
    }
      

  15.   

    SqlCommand cmd = new SqlCommand(sqlstr,cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
    你这几行是怎么回事?把SqlCommand cmd = new SqlCommand(sqlstr,cn);删了
    SqlDataAdapter da = new SqlDataAdapter(cmd);后面少了个参数 加上
    SqlDataAdapter da = new SqlDataAdapter(cmd,cn);
      

  16.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body style="text-align: left" background="image/cus.gif">
        <form id="form1" runat="server">
        <div style="text-align: center" title="查询">
            <asp:Menu ID="Menu1" runat="server" BackColor="#F7F6F3" DynamicHorizontalOffset="2"
                Font-Names="Verdana" Font-Size="1.2em" ForeColor="#7C6F57" Height="25px" Orientation="Horizontal"
                StaticSubMenuIndent="10px" Width="622px" Font-Bold="True">
                <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
                <DynamicMenuStyle BackColor="#F7F6F3" />
                <StaticSelectedStyle BackColor="#5D7B9D" />
                <DynamicSelectedStyle BackColor="#5D7B9D" />
                <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                <Items>
                    <asp:MenuItem NavigateUrl="~/Default2.aspx" Text="录入" Value="录入"></asp:MenuItem>
                    <asp:MenuItem NavigateUrl="~/Default3.aspx" Text="查询" Value="查询"></asp:MenuItem>
                </Items>
                <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />
            </asp:Menu>
            <br />
            <asp:Label ID="Label1" runat="server" Text="报检号" Width="102px"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
            <br />
            <asp:Label ID="Label2" runat="server" Text="总运单号" Width="102px"></asp:Label>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
            <br />
            <asp:Label ID="Label3" runat="server" Text="分运单号" Width="102px"></asp:Label>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
            <br />
            <asp:Button ID="Button1" runat="server" Height="24px" OnClick="Button1_Click" Text="查询"
                Width="101px" />
            &nbsp;
            <asp:Button ID="Button2" runat="server" Height="24px" Text="保存" Width="101px" OnClick="Button2_Click" />
            &nbsp;
            <br />
            <br />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="637px" OnRowCommand="GridView1_RowCommand">
                <Columns>
                    <asp:BoundField DataField="jkrq" HeaderText="进库日期" />
                    <asp:BoundField DataField="bjh" HeaderText="报检号" />
                    <asp:BoundField DataField="zydh" HeaderText="总运单号" />
                    <asp:BoundField DataField="fydh" HeaderText="分运单号" />
                    <asp:BoundField DataField="js" HeaderText="件数" />
                    <asp:BoundField DataField="cysj" HeaderText="查验时间" />
                    <asp:BoundField DataField="qyg" HeaderText="启运国" />
                    <asp:BoundField DataField="ck" HeaderText="仓库" />
                    <asp:TemplateField HeaderText="查验情况" FooterText="cyqk">
                        <ItemTemplate>
                            <asp:RadioButton ID="RadioButton1" runat="server" GroupName="rdo" Text="合格" />
                            <asp:RadioButton ID="RadioButton2" runat="server" GroupName="rdo" OnCheckedChanged="RadioButton2_CheckedChanged"
                                Text="不合格" />&nbsp;
                    <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem>有本,有标</asp:ListItem>
                        <asp:ListItem>有本,无标</asp:ListItem>
                        <asp:ListItem>总单不符</asp:ListItem>
                        <asp:ListItem>分单不符</asp:ListItem>
                    </asp:DropDownList>
                    &nbsp;&nbsp;
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="bz" HeaderText="备注" />
                </Columns>
            </asp:GridView>
            &nbsp;
            <br />
        
        </div>
            &nbsp;
        </form>
    </body>
    </html>
      

  17.   

    SqlCommand cmd = new SqlCommand(sqlstr,cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
    你这几行是怎么回事?把SqlCommand cmd = new SqlCommand(sqlstr,cn);删了
    SqlDataAdapter da = new SqlDataAdapter(cmd);后面少了个参数 加上
    SqlDataAdapter da = new SqlDataAdapter(cmd,cn);
      

  18.   

    还有你没有把单选按钮的 AutoPostBack属性设置成true啊
      

  19.   

    zwwlovezy1(Eminem)办法可行.关键你别死套程序.要灵活点
    RadioButton的AutoPostBack属性设置为真,把方法写到RadioButton1_CheckedChanged里
      

  20.   


    你肯定是 忘加autoPostBack了吧
      

  21.   

    解决方案:
    1.如果是服务器端,在GridView1_RowCommand事件中 使用FindControl,找到控件,处理
    2.如果可客户端,在GridView生成的时候,得到控件ID,然后写JS代码,控制流程