Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 January 29th, 2004, 08:01 AM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to poison_king
Default DropDownList selectedindex retrieval

I have a DropDownList which gets populated on Edit event of the DataGrid. But on Update event the selected index always gives the first index value even for other selected item.
What could be the problem and the solution for it? The part below is the code used in C#.

<asp:datagrid id="TransferGroupDataGrid" runat="server" OnUpdateCommand="TransferGroupDataGrid_UpdateComma nd" DataKeyField="rec_id" PageSize="25" AllowPaging="True" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" GridLines="Vertical" AutoGenerateColumns="False" Width="100%" ForeColor="Black" OnPageIndexChanged="TransferGroupDataGrid_PageInde xChanged">
<Columns>
<asp:BoundColumn Visible="False" DataField="new_jamaat_id" ReadOnly="True" HeaderText="New Jamaat ID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="New Mouze Name">
<ItemTemplate>
    <asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.new_jamaat_name") %>'>
    </asp:Label>
</ItemTemplate>
<EditItemTemplate>
    <asp:DropDownList id=JamaatListBox runat="server" DataValueField="jamaat_id" DataTextField="jamaat_name1" DataSource="<%# GetJamaatList() %>">
    </asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Allot"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>


protected void TransferGroupDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
  if(IsPostBack)
   {
    Response.Write(((DropDownList)e.Item.FindControl(" JamaatListBox")).SelectedItem.Value) ;
   }
}

Cheers,
Nagraj(poison_king)

 
Old January 29th, 2004, 08:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

How are you binding the initial data for the grid? In Page_Load?
If so, do you only bind when there is no PostBack? It could be that your initial data is reloaded in the grid upon PostBack. This also causes the drop-down to be rebound to the data, overwriting the selected item in the drop down.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 29th, 2004, 09:12 AM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to poison_king
Default

Thanks Imar .. it worked .

 
Old September 17th, 2004, 02:16 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I have the same problem. Allways the first value in the list is returned in the Update handler on:
((DropDownList)e.Item.FindControl("myDDL")).Select edItem.Text

I put a break in my private void BindData() and it definitely is called after stumbling in the Update handler.

Any ideas?


 
Old September 19th, 2004, 04:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you post the relevant parts of your code? I think that somehow the drop-down is still bound again on PostBack, overwriting its SelectedIndex value....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Death Valley '69 by Sonic Youth (Track 8 from the album: Bad Moon Rising) What's This?
 
Old September 21st, 2004, 09:44 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
there is no need for binding DropDownList in such situations,if you bind it,your SelectedIndex will reset ....
just for the first PageLoad you should bind your DropDownList somewhere like ItemDataBound event(after binding your DataGrid),
if you want to change the contents of your DropDownList you should again bind it(by knowing that SelectedIndex will reset again)
meanwhile,when you bind your grid your DropDownList will be bound(because it is the child of your datagrid)
also have a look at this :
http://p2p.wrox.com/topic.asp?TOPIC_ID=5756
it might help you more...

--------------------------------------------
Mehdi.:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectedIndex in datalist dhoward VB.NET 2002/2003 Basics 0 August 28th, 2008 10:15 AM
how to set selectedindex azitanosrati General .NET 16 December 1st, 2006 02:25 PM
GridView.SelectedIndex Prop SteveP55419 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 8th, 2006 09:08 PM
Combobox SelectedIndex Issue kancha C# 7 July 26th, 2006 07:14 AM
Grab SelectedIndex Number phungleon Classic ASP Basics 6 May 18th, 2004 10:14 AM





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