我有以下设置,一个ddl(ddlProd,radBuyer)和自动完成文本框(txtProdAC,radProd),当填充它们并选择它们各自的单选按钮时,会生成数据的网格视图......可爱的东西
protected void btSearch_Click(object sender, EventArgs e)
{
lqPackWeights.WhereParameters.Clear();
ControlParameter cp = new ControlParameter();
cp.Type = TypeCode.String;
if (radBuyer.Checked)
{
cp.ControlID = "ddlProd";
cp.PropertyName = "SelectedValue";
}
if (radProd.Checked)
{
cp.ControlID = "tbxProdAC";
cp.PropertyName = "Text";
}
else
{
cp.ControlID = "lbRadMiss";
cp.PropertyName = "Text";
lbRadMiss.Text = "Please check appropriate radio button before you attempt a search";
}
cp.Name = "IDDesc";
lqPackWeights.WhereParameters.Add(cp);
GridView1.DataSourceID = "lqPackWeights";
GridView1.DataBind();
}
我停留在else
部分,这样如果用户点击“搜索”按钮而没有选中单选按钮,就会出现一个标签并说“请检查......等等”
这很好但我有一个小问题。如果用户产生此验证(其他),则他或她将自然地点击相应的单选按钮,然后再次单击搜索。但是,当遵循此过程时,我的代码似乎忽略了它的工作,并且没有获取ddl的选定值或tbxProdAC中的文本。 else标签保留,网格视图保持为空。
有人可以指出我的方向。
答案 0 :(得分:1)
else
{
cp.ControlID = "lbRadMiss";
cp.PropertyName = "Text";
lbRadMiss.Text = "Please check appropriate radio button before you attempt a search";
///Include this line
return;
}
答案 1 :(得分:1)
else if (radProd.Checked)
(而不仅仅是空的if)
答案 2 :(得分:1)
您想要以下内容吗?
if (radBuyer.Checked)
{
cp.ControlID = "ddlProd";
cp.PropertyName = "SelectedValue";
}
else if (radProd.Checked)
{
cp.ControlID = "tbxProdAC";
cp.PropertyName = "Text";
}
else
{
cp.ControlID = "lbRadMiss";
cp.PropertyName = "Text";
lbRadMiss.Text = "Please check appropriate radio button before you attempt a search";
}