English 中文(简体)
If / else order sequence issue
原标题:

I have the following set up, a ddl (ddlProd, radBuyer) and autocomplete text box (txtProdAC, radProd) that when populated and their respective radio buttons are selected, a grid view of the data is produced...lovely stuff.

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();         

}   

I stuck in the else section so that should a user hit the Search button without a radio button being checked, a label would appear and saying "Please check...etc"

This works fine but I have a slight problem. If a user produces this validation (the else), he or she would then naturally hit the appropriate radio button and then click search again. However, when this process is followed, my code seems to ignore it s job and does not pick up either the selected value for the ddl or the text from the tbxProdAC. The else label remains and the grid view remains empty.

Can someone point me in the direction with this.

最佳回答

you probably want

else if (radProd.Checked)

(instead of just the empty if)

问题回答
else    
{   
    cp.ControlID = "lbRadMiss";   
    cp.PropertyName = "Text";   
    lbRadMiss.Text = "Please check appropriate radio button before you attempt a search";  


    ///Include this line
    return;

} 

Do you want the following instead?

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";   
}   




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签