在gridview中插入一列TemplateField,然后在ItemTemplate中插入了2个RadioButton和DropDownList,如何让选中第2个RadioButton时,DropDownList可见。
解决方案 »
- 执行JavaScript代码, 页面也会闪烁吗?
- 关于forms验证 自动跳转~~~~~ 谢谢~~~
- 在VS2005里面,如何实现异步操作?
- 数据源控件的生命周期
- 如何将Gridview 的Commandfield “编辑”“ 删除” 放到所有数据列的右边
- freetextbox文件保存
- 学together而弃Rose的几大理由!!!!!!
- 我准备买《vb.net高级编程》和《asp.net入门经典-vb.net篇》两本书,同时配合联机帮助MSDN,开始全面的学习.net。有一年的vb和半年的asp
- 如何传递变量,比如在sql语句中使用变量?
- MVC4, Area中Ajax.ActionLink访问[HttpPost]属性的Action无效
- 如果我想用类似Aplication_onStart(...) Aplication_End()之类的方法在vs2005里面那里找?
- 弹出指定大小的窗口,在线等!!!
{
foreach(GridViewRow gvr in GridView1.Rows)
{
RadioButton rbtn=(RadioButton)gvr.FindControl("RadioButton2");//第二个
if(rbtn.Checked)
{
DropDownList ddl=(DropDownList)gvr.FindControl("DropDownList1");
ddl.Visible=true;
}
}
}
我查询了1条记录,点了RadioButton2之后没有反应。
要是在加一个模板列 里面放上按钮 然后选中RadioButton2的话 能隐藏你选的拿行的下拉列表
上面给的代码没问题
就是点击单选按钮没有触发模板列事件
你模板列里不是有两个单选按钮吗 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;
}
}
}
{
foreach (GridViewRow gvr in GridView1.Rows)
{
RadioButton rbtn = (RadioButton)gvr.FindControl("RadioButton2");//第二个
if (rbtn.Checked)
{
DropDownList ddl = (DropDownList)gvr.FindControl("DropDownList1");
ddl.Visible = false;
}
}
}
放在模板中的那个RadioButton2的点击事件中
因为要触发模板列事件 好象只有Button才可以
所以只能写在RadioButton2的点击事件里了
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)
{
}
}
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);
<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" />
<asp:Button ID="Button2" runat="server" Height="24px" Text="保存" Width="101px" OnClick="Button2_Click" />
<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="不合格" />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>有本,有标</asp:ListItem>
<asp:ListItem>有本,无标</asp:ListItem>
<asp:ListItem>总单不符</asp:ListItem>
<asp:ListItem>分单不符</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bz" HeaderText="备注" />
</Columns>
</asp:GridView>
<br />
</div>
</form>
</body>
</html>
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);
RadioButton的AutoPostBack属性设置为真,把方法写到RadioButton1_CheckedChanged里
你肯定是 忘加autoPostBack了吧
1.如果是服务器端,在GridView1_RowCommand事件中 使用FindControl,找到控件,处理
2.如果可客户端,在GridView生成的时候,得到控件ID,然后写JS代码,控制流程