Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2008, 06:47 AM
Authorized User
 
Join Date: Apr 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default help related to a SelectedIndexChanged event

help related to a SelectedIndexChanged event of a dropdownlist inside a GridView control in asp.net 2.0


I am using asp.net 2.0.
I have a dropdownlist control inside a gridview control. On selecting an item in the dropdownlist, I am able to display related data in other two columns of the grid in the same row. But the problem -> the moment i choose another item from the dropdownlist data just get cleared from the previous line. This is happening in every row.

protected void GridView1_SelectedIndexChanged(object sender,
    EventArgs e)
{
  string selectedtext = ((DropDownList)
         GridView1.SelectedRow.FindControl
                 ("ddlicode")).SelectedItem.Value;
         GridViewRow row = GridView1.SelectedRow;

         comm = new SqlCommand("select item_code,item_desc from
             ItemMast where item_desc='" + selectedtext + "'", conn);
         conn.Open();
         SqlDataReader dr = comm.ExecuteReader();
         while (dr.Read())
         {
            ((Label)row.FindControl("lblicode")).Text = dr.GetValue
                  (0).ToString().Trim();
            ((Label)row.FindControl("lblidesc")).Text = dr.GetValue
                  (1).ToString().Trim();
         }
         conn.Close();
     }


 
Old May 22nd, 2008, 04:41 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is what I think maybe going on. I have been off PCs for 4 months thanks to optic neuritis so I am feeling a little rusty.

I had a gridview that updated its datasource via code. I wanted to export that to an excel file so I tried to tell the new virtual datagrid to use the same datasource as the grid that is being displayed. Wanna know what I found? I found no data in there. Anybody can correct me but if there is no datasource on the front end (html side) or it isn't getting fed the data source and then you get it from the control after that in the same instance then it will not be retained. Similar to variables losing their value after the page comes back. You may have to save the state of that Gridview during the initial alteration before the system returns everything to the page. Basically, after your update, save the state in a session or database and then call it back in front to repopulate if it is not an empty session. The state of that control is not being saved. Now, I am rusty on viewstates also but I heard there might be a way to tell the control to hold on to its state but the rest of the forum who has been actively programming for the past 4 months can answer that, I have to get caught up so I don't look like an idiot when I return to work. :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
selectedindexchanged event not firing kaliaparijat ASP.NET 2.0 Professional 1 June 5th, 2008 08:58 AM
DropDownList SelectedIndexChanged Event does not davej ASP.NET 2.0 Basics 3 October 12th, 2007 10:20 AM
GridView SelectedIndexChanged event bnorg ASP.NET 2.0 Professional 1 July 7th, 2007 01:14 AM
SelectedIndexChanged Event doesn't fire ddudley3 ASP.NET 2.0 Professional 7 February 6th, 2006 10:47 AM
listbox event SelectedIndexChanged alyeng2000 ASP.NET 1.0 and 1.1 Basics 2 December 22nd, 2003 10:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.