Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click on Search Applicant Button By Applicant Id filled on Grid but when i choose Applicant name and click on button Not show grid or any data.

C#
 if (!IsPostBack)
        {
            ddlHeader.Items.Insert(0, "---Select---");
            ddlHeader.Items.Insert(1, "ApplicantID");
            ddlHeader.Items.Insert(2, "ApplicantName");
            

            GridView2.DataSource = applic.ShowApplicant();
            GridView2.DataBind();
        }



<pre lang="C#">
<b>Method 1</b>
public DataSet GetApplicantDataByID(string ApplicantID)
    {

        ds = new DataSet();
        ds = SqlHelper.ExecuteDataset(con, CommandType.Text, &quot;select * from Applicant where ApplicantId=&#39;&quot;+ApplicantID +&quot;&#39;&quot;);
        return ds;
    }

<b>Method 2</b>
    public DataSet GetApplicantDataByName(string Name)
    {

        ds = new DataSet();
        ds = SqlHelper.ExecuteDataset(con, CommandType.Text, &quot;select * from Applicant where ApplicantName=&#39;&quot; + ApplicantName + &quot;&#39;&quot;);
        return ds;
    }




&lt;pre lang=&quot;C#&quot;&gt;GetApplicantDataByID(txtApp.Text)

&amp;lt;pre lang=&amp;quot;C#&amp;quot;&amp;gt;protected void btnSearchApplicant_Click(object sender, EventArgs e)
   {
       if (ddlHeader.SelectedIndex == 1)
       {
            GridView2.DataSource = applic.GetApplicantDataByID(txtApp.Text);
           GridView2.DataBind();
       }

       else if (ddlHeader.SelectedIndex == 2)
       {

           GridView2.DataSource = applic.GetApplicantDataByName(txtApp.Text);
           GridView2.DataBind();

       }

       else
       {
       btnSearchApplicant.Visible=false;
       txtApp.Visible=false;
       }

   }&amp;lt;/pre&amp;gt;&lt;/pre&gt;</pre>
Posted
Comments
dan!sh 25-Jan-16 2:14am    
Update your question with button click event handler. I suspect you are not rebinding the grid after postback.
deepankarbhatnagar 25-Jan-16 2:29am    
Not getting your query, please explain
Sinisa Hajnal 25-Jan-16 2:35am    
Show the code of ShowApplicant. Did you check that it returns data when ApplicantName is selected?

Not that having ApplicantName and ApplicantID in user interface, seen by the user is bad design. User should see friendly "normal" language something like:
Search by: <- label
Identifier <- combobox item 1
Applicant Name <- combobox item 2

1 solution

I'm guessing you are assuming that if it is a postback one of your buttons has been pressed. While this does kind of work, when you have multiple buttons there is no way of knowing which button caused the postback. So you need to implement click events for the buttons and put the relevant code in the relevant click event.
 
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