Link to home
Start Free TrialLog in
Avatar of Johny Bravo
Johny Bravo

asked on

SelectedIndexchanged of Gridview

Hi Experts,
Let me explain the scenario.I am having some search criterua,accordingly data is displayed in the Gridview.Further on selection of Gridview row I am showing that data in the text boxes below.
Now the problem,if I search for a particular record,that displayed in the Gridview,when I click that row,the details are filled in the textboxes.Upto this it is fine.But if I search again for different record,Gridview displays that record but the textboxes below it are still showing previous data.

Can I show the first row in the Gridview as selected and the data in the textbox,after each search?
Avatar of agsapt
agsapt
Flag of Indonesia image

could you please post pseudo codeof your program ? From what you just explained here, I believe you should do a complete clear on both gridview and textboxes before you launch any search against your data.
Avatar of Johny Bravo
Johny Bravo

ASKER

in page load
  if (!IsPostBack)
        {
                      fillAcquisitionDetails();
        }

 private void fillAcquisitionDetails()
    {
SqlCommand cmd = new SqlCommand("spMultipleKhates", cnn.connection());
        cmd.CommandType = CommandType.StoredProcedure;

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        //dt = cnn.SelectRecord(sqlstr);
        this.gvAcquisitionDetails.DataSource = ds;
         this.gvAcquisitionDetails.DataBind();
       
    }

  protected void gvAcquisitionDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
  this.txtNewSurveyNo.Text = this.gvAcquisitionDetails.SelectedRow.Cells[5].Text;
       this.txtTotalArea712.Text = this.gvAcquisitionDetails.SelectedRow.Cells[6].Text;
       this.txtAssessment.Text = this.gvAcquisitionDetails.SelectedRow.Cells[7].Text;
       this.txtOldSNo.Text = this.gvAcquisitionDetails.SelectedRow.Cells[8].Text;
       this.txtAreaAcquired.Text = this.gvAcquisitionDetails.SelectedRow.Cells[9].Text;
       this.txtTotAssessment.Text = this.gvAcquisitionDetails.SelectedRow.Cells[10].Text;
       this.txtAssessmentRateHa.Text = this.gvAcquisitionDetails.SelectedRow.Cells[11].Text;
}
protected void btnSearch_Click(object sender, EventArgs e)
    {
  SqlCommand cmd = new SqlCommand("spMultipleKhates_Search", cnn.connection());
        cmd.CommandType = CommandType.StoredProcedure;

        int vid;
        if (this.ddlVillage.SelectedValue != "Select Village")
        {
            vid = Convert.ToInt32(this.ddlVillage.SelectedValue);
            cmd.Parameters.Add("@villageid", SqlDbType.Int).Value = vid;
        }
        else
        {
            cmd.Parameters.Add("@villageid", SqlDbType.Int).Value = null;
        }

        if (this.ddlLACaseNo.SelectedValue != " ")
        {
            cmd.Parameters.Add("@lacno", SqlDbType.NVarChar).Value = this.ddlLACaseNo.SelectedValue;
        }
        else
        {
            cmd.Parameters.Add("@lacno", SqlDbType.NVarChar).Value = null;
        }
 SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        this.gvAcquisitionDetails.DataSource = ds;
        this.gvAcquisitionDetails.DataBind();
    }



If I click Grid row first time,then search again,until I click grid row again,only the previous data is visible.
ASKER CERTIFIED SOLUTION
Avatar of paololabe
paololabe
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Let me put it in squence :

1> Req is to pupulate the text boxes on selecting of an grid Row (SelectIndex Event),

2> So if you need to populate the textboxes again by firing the event expliicty (Clicking on the Row Again)

3> if u want the text boxes to be empty and reloaded with new search row,then in
btnSearch_Click event ,make the textboxes bound to the newly fetched data from the  
dataSet ,and also if u r doing any color coding to show the selected Row ,here also u can manually make the color change of the first row.

Hope this will resolve the issue.
Thanks.That's what Iwas looking for.