Reputation: 839
I am new to desktop application development.
I have a search button through which the grid is filled from the database records.
First I put the button in the group box and debugged the program and found that the click
event was firing twice. Then I placed same button out of the text box and found that the event is getting fired only once.
My Button_Click()
event contains the following code:
private void btnSearch_Click(object sender, EventArgs e)
{
string query = null;
if (txtBillNo.Enabled && txtBillNo.Text.Trim().Length != 0)
{
query = "Select BillNo,PartyName,City,State,FORMAT(BillDt,'dd-mm-yyyy')as Dt from BillMaster where BillNo=" + Convert.ToInt32(txtBillNo.Text.Trim());
FillGrid(query);
}
else if (txtName.Enabled && txtName.Text.Trim().Length != 0)
{
query = "Select BillNo,PartyName,City,State,FORMAT(BillDt,'dd-mm-yyyy')as Dt from BillMaster where UCASE(PartyName) like '" + txtName.Text.Trim().ToUpper() + "'";
FillGrid(query);
}
else
{
MessageBox.Show("Enter Value First");
if (rdbName.Enabled)
{
txtName.Focus();
}
else if (rdbBillNo.Enabled)
{
txtBillNo.Focus();
}
}
}
The event handler is bound in the Form_Load() event using:
btnSearch.Click+=new EventHandler(btnSearch_Click);
What should I do to fire the click event after placing the button in the group box.
Please help.
Upvotes: 0
Views: 176
Reputation: 12954
I think the contents of your btnSearch_Click
is irrelevant. I am almost sure that btnSearch.Click
is assigned twice. Once in your Form_Load
and possibly somewhere else, perhapse in your code-behind file?
Upvotes: 1