Solved

SelectedIndexchanged of Gridview

Posted on 2009-07-13
5
345 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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