Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi guys!
I have two text boxes and an image button. If I input something to both text boxes, I will click the Image button to search for the existing record in my database (SQL SERVER 2008-R2) and will display at my grid view. It works fine to me BUT I have a requirement that after searching and it find a record that matches the two text boxes,display the record to grid view and the two text boxes will be disabled.But if no records found, the two text boxes will remain as enabled. The problem now is that I do not know on how to do that. Please help me :)
Posted
Comments
ChauhanAjay 1-Sep-14 0:03am    
Are you using a datatable to bind the data to the grid.
Gihan Liyanage 1-Sep-14 1:00am    
You just need to TextBox.Enabled= false; if you have not empty data source. If you provide existing code, then people may give you the code.

C#
if(txt1.Text!="" && txt2.Text!="")
{
    DataSet ds=new Dataset();
    ds=//Put data into dataset.
    if(ds.Tables[0].Rows.Count>0)
    {
        // Bind your grid here..
        // Disable your Textbox1 and Textbox2
        txt1.Enabled=false;
        txt2.Enabled=false;
    }

}
 
Share this answer
 
Get Row count of grid view
C#
gridView1.Rows.Count()

Then if row count >0 you need to disable text boxes.

C#
TextBox.Enabled = false
 
Share this answer
 
You Can add Message No Record Found
or
disable textbox by using Enabled = false property of textbox
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900