Solved

SelectedIndexchanged of Gridview

Posted on 2009-07-13
5
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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