Solved

SelectedIndexchanged of Gridview

Posted on 2009-07-13
5
337 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.That's what Iwas looking for.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

6 Experts available now in Live!

Get 1:1 Help Now