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?
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?
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.
ASKER
in page load
if (!IsPostBack)
{
fillAcquisitionDetails();
}
private void fillAcquisitionDetails()
{
SqlCommand cmd = new SqlCommand("spMultipleKhat es", cnn.connection());
cmd.CommandType = CommandType.StoredProcedur e;
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_Selec tedIndexCh anged(obje ct sender, EventArgs e)
{
this.txtNewSurveyNo.Text = this.gvAcquisitionDetails. SelectedRo w.Cells[5] .Text;
this.txtTotalArea712.Text = this.gvAcquisitionDetails. SelectedRo w.Cells[6] .Text;
this.txtAssessment.Text = this.gvAcquisitionDetails. SelectedRo w.Cells[7] .Text;
this.txtOldSNo.Text = this.gvAcquisitionDetails. SelectedRo w.Cells[8] .Text;
this.txtAreaAcquired.Text = this.gvAcquisitionDetails. SelectedRo w.Cells[9] .Text;
this.txtTotAssessment.Text = this.gvAcquisitionDetails. SelectedRo w.Cells[10 ].Text;
this.txtAssessmentRateHa.T ext = this.gvAcquisitionDetails. SelectedRo w.Cells[11 ].Text;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("spMultipleKhat es_Search" , cnn.connection());
cmd.CommandType = CommandType.StoredProcedur e;
int vid;
if (this.ddlVillage.SelectedV alue != "Select Village")
{
vid = Convert.ToInt32(this.ddlVi llage.Sele ctedValue) ;
cmd.Parameters.Add("@villa geid", SqlDbType.Int).Value = vid;
}
else
{
cmd.Parameters.Add("@villa geid", SqlDbType.Int).Value = null;
}
if (this.ddlLACaseNo.Selected Value != " ")
{
cmd.Parameters.Add("@lacno ", SqlDbType.NVarChar).Value = this.ddlLACaseNo.SelectedV alue;
}
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.
if (!IsPostBack)
{
fillAcquisitionDetails();
}
private void fillAcquisitionDetails()
{
SqlCommand cmd = new SqlCommand("spMultipleKhat
cmd.CommandType = CommandType.StoredProcedur
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
//dt = cnn.SelectRecord(sqlstr);
this.gvAcquisitionDetails.
this.gvAcquisitionDetails.
}
protected void gvAcquisitionDetails_Selec
{
this.txtNewSurveyNo.Text = this.gvAcquisitionDetails.
this.txtTotalArea712.Text = this.gvAcquisitionDetails.
this.txtAssessment.Text = this.gvAcquisitionDetails.
this.txtOldSNo.Text = this.gvAcquisitionDetails.
this.txtAreaAcquired.Text = this.gvAcquisitionDetails.
this.txtTotAssessment.Text
this.txtAssessmentRateHa.T
}
protected void btnSearch_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("spMultipleKhat
cmd.CommandType = CommandType.StoredProcedur
int vid;
if (this.ddlVillage.SelectedV
{
vid = Convert.ToInt32(this.ddlVi
cmd.Parameters.Add("@villa
}
else
{
cmd.Parameters.Add("@villa
}
if (this.ddlLACaseNo.Selected
{
cmd.Parameters.Add("@lacno
}
else
{
cmd.Parameters.Add("@lacno
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this.gvAcquisitionDetails.
this.gvAcquisitionDetails.
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
Thanks.That's what Iwas looking for.