Solved

SelectedIndexchanged of Gridview

Posted on 2009-07-13
5
342 Views
Last Modified: 2013-11-07
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?
0
Comment
Question by:johny_bravo1
5 Comments
 
LVL 5

Expert Comment

by:agsapt
ID: 24838191
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.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 24838248
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.
0
 
LVL 8

Accepted Solution

by:
paololabe earned 500 total points
ID: 24838358
I would ad the folloving line after each search, in btnSearch_Click method after databind

paolo.





gvAcquisitionDetails.selectedIndex=0;

gvAcquisitionDetails_SelectedIndexChanged(gvAcquisitionDetails, null);

Open in new window

0
 
LVL 3

Expert Comment

by:DreamsTech
ID: 24838385
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.
0
 
LVL 8

Author Closing Comment

by:johny_bravo1
ID: 31602750
Thanks.That's what Iwas looking for.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now