为什么在下面的条件就不起作用?

flashasp 2004-06-29 03:11:35
现有RadioButton1,和RadioButton2

<asp:RadioButton id="RadioButton1" runat="server" Text="个人会员" GroupName="sex" Runat=server></asp:RadioButton>
<asp:RadioButton id="RadioButton2" runat="server" Text="公司会员" GroupName="sex" Runat=server></asp:RadioButton>
---------------------------------------------------------------------------------
为什么在下面的条件就不起作用?
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string sql="";

if (RadioButton1.Checked==true)//为什么这个条件不起作用?
{
sql="select username,password from person order by id desc";
}
else

{
sql="select UserName,Password from company order by id desc";
}

if(!Geonado_Data.datareader(sql))
{
Response.Write("<script>alert('用户名未注册!')</script>");
return;
}
sql="select id from person where username='"+UserName.Value+"'and password='"+password.Value+"' ";
if(!Geonado_Data.datareader(sql))
{
Response.Write("<script>alert('密码错误!')</script>");
return;
}
else
{
Session["UserName"]=UserName.Value;
Response.Redirect("index.asp");

}

}
...全文
179 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
flashasp 2004-06-29
  • 打赏
  • 举报
回复
这样修改就对拉^_^
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string sql="",url="";
if (RadioButton1.Checked==true)
{
sql="select id from person where username='"+UserName.Value+"'and password='"+password.Value+"' ";
url="person/index.asp";
}
else

{
sql="select id from company where username='"+UserName.Value+"'and password='"+password.Value+"' ";
url="company/index.asp";
}
if(!Geonado_Data.datareader(sql))
{
Response.Write("<script>alert('用户名未注册!')</script>");
return;
}



if(!Geonado_Data.datareader(sql))
{
Response.Write("<script>alert('密码错误!')</script>");
return;
}
else
{
Session["UserName"]=UserName.Value;
Response.Redirect(url);

}

}
flashasp 2004-06-29
  • 打赏
  • 举报
回复
晕哦,重要看出来拉,问题在这里:
sql="select id from person where username='"+UserName.Value+"'and password='"+password.Value+"' ";
刚开始的两个判断对这个SQL语句根本就不起作用^_^
我知道怎么改拉,粗心的家伙!
flashasp 2004-06-29
  • 打赏
  • 举报
回复
SQL语句string sql1="select top 8 id,biaoti,data from [gonggao] order by id desc";
^_^与我的登陆程序是无关的1!
要不我把
select UserName,Password from company order by id desc改为

select UserName,Password from company 测试一哈^_^

exboy 2004-06-29
  • 打赏
  • 举报
回复
代码看上去没有什么问题,把

this.RadioButton1.CheckedChanged += new System.EventHandler(this.RadioButton1_CheckedChanged);
this.RadioButton2.CheckedChanged += new System.EventHandler(this.RadioButton2_CheckedChanged);

两行去掉试试
zljblue 2004-06-29
  • 打赏
  • 举报
回复
请注意你的SQL语句string sql1="select top 8 id,biaoti,data from [gonggao] order by id desc";永远都是按这个条件查询,怎么可能会改变查询的结果呢
flashasp 2004-06-29
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using geonado_space;//引用class类的命名空间geonado_space

namespace WebAppPowerDataGridTest
{
public class _default : System.Web.UI.Page
{

data Geonado_Data=new data();
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.HtmlControls.HtmlInputText UserName;
protected System.Web.UI.HtmlControls.HtmlInputText password;
protected System.Web.UI.WebControls.RadioButton RadioButton2;
protected System.Web.UI.WebControls.RadioButton RadioButton1;
protected System.Web.UI.WebControls.DataGrid DG_board;
protected System.Web.UI.HtmlControls.HtmlInputImage Image1;

public void bind()//绑定所有的DATAGRID
{
string sql1="select top 8 id,biaoti,data from [gonggao] order by id desc";
DataSet ds_board=Geonado_Data.dbbind(sql1);
DG_board.DataSource=ds_board.Tables["mytable"].DefaultView;
DG_board.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
bind();


}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.RadioButton1.CheckedChanged += new System.EventHandler(this.RadioButton1_CheckedChanged);
this.RadioButton2.CheckedChanged += new System.EventHandler(this.RadioButton2_CheckedChanged);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.DG_board.SelectedIndexChanged += new System.EventHandler(this.DG_board_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string sql="";
if (RadioButton1.Checked==true)
{
sql="select username,password from person order by id desc";
}
else

{
sql="select UserName,Password from company order by id desc";
}
if(!Geonado_Data.datareader(sql))
{
Response.Write("<script>alert('用户名未注册!')</script>");
return;
}
sql="select id from person where username='"+UserName.Value+"'and password='"+password.Value+"' ";
if(!Geonado_Data.datareader(sql))
{
Response.Write("<script>alert('密码错误!')</script>");
return;
}
else
{
Session["UserName"]=UserName.Value;
Response.Redirect("index.asp");

}

}


}
}
-----------------------------------------------全部代码就这些,各位帮我看看
flashasp 2004-06-29
  • 打赏
  • 举报
回复
设AutoPostBack为true候还是一样的
touger 2004-06-29
  • 打赏
  • 举报
回复
你看看是不是radiobutton的AutoPostBack设为了false,应该设为true
如果不马上回贴,不会更改radiobutton的checked的值
flashasp 2004-06-29
  • 打赏
  • 举报
回复
我的Page_Load里面还没东西
zhlzl 2004-06-29
  • 打赏
  • 举报
回复
同意楼上的, 把Page_Load的代码贴出来
Jinniu 2004-06-29
  • 打赏
  • 举报
回复
应该是你page_load里面初始化时出的问题!把你的page_load部分贴出来看看!
NoFile 2004-06-29
  • 打赏
  • 举报
回复
当PostBack时不要对RadioButton1进行数据绑定,不然就被初始化了
使用
if (!Page.IsPostBack)
……绑定数据
chido 2004-06-29
  • 打赏
  • 举报
回复
呵呵,当然一样了,现在重要的是你在选择RadioButton1后,有地方将他初始化为未选中状态了
flashasp 2004-06-29
  • 打赏
  • 举报
回复
if (RadioButton1.Checked==true)
===>
if (RadioButton1.Checked)
还是一样的啊
ml_net 2004-06-29
  • 打赏
  • 举报
回复
if (RadioButton1.Checked==true)
===>
if (RadioButton1.Checked)
cpp2017 2004-06-29
  • 打赏
  • 举报
回复
看起来没有问题, 看有没有在程序的其他的地方把2的checked设为true了?
仙人掌 2004-06-29
  • 打赏
  • 举报
回复
page_load()
------------------
if(!IsPostBack)
{
//这里初始化页面
}
chido 2004-06-29
  • 打赏
  • 举报
回复
判断一下RadioButton1.Checked的值到底是什么,查看程序结构,是不是在提交后将页面内容给初始化了

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧