Click here to Skip to main content
15,891,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display records(search a records)when selecting a value from dropdown list and values should be displayed in texbox after button click?
Posted
Comments
CRDave1988 15-Feb-12 3:54am    
what u have done so far? where u facing problem?
ythisbug 15-Feb-12 4:02am    
is it in correct format???m getting error like object reference is not set to an instance of an object..


protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
{
SearchTestCasePL stPL = new SearchTestCasePL();
stPL.TID = ddlTestCase.SelectedItem.Text;


SearchTestCaseBLL stBLL = new SearchTestCaseBLL();
DataTable dt = new DataTable();
dt = stBLL.SearchTestCase(stPL);

if (dt.Rows.Count > 0)
{
txtBuildNo.Text = dt.Rows[0]["BuildNo"].ToString();
txtTestCase.Text = dt.Rows[0]["TID"].ToString();
ddlStatus.SelectedItem.Text = dt.Rows[0]["Status"].ToString();
txtSDate.Text = dt.Rows[0]["StarDate"].ToString();
txtEDate.Text = dt.Rows[0]["EndDate"].ToString();
txtExecution.Text = dt.Rows[0]["ExecutionTime"].ToString();
}

this s my code..when i slect single items from drop downs and click search button i want to show tat records in textbox..perticular items record..understood??
CRDave1988 15-Feb-12 4:06am    
ok but what problem u r facing code dose not affect or Exception is thrown, or function is not called or anything else.
ythisbug 15-Feb-12 4:18am    
code dose not affect and function is not calld.
CRDave1988 15-Feb-12 4:22am    
put debug point on line 'if (dt.Rows.Count > 0)' and see what value is stored in dt is it contain value or not.

1 solution

Hi,

if you are getting object reference exception, one of the cause is you are trying to convert null value into ToString.

as you can see in your code

C#
txtBuildNo.Text = dt.Rows[0]["BuildNo"].ToString();


should be changed with
C#
txtBuildNo.Text = Convert.ToString(dt.Rows[0]["BuildNo"]);

similarly check all the casting properly for this exception resolution.

hope this will solve your problem.

thanks
-amit.
 
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