Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
| Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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
  #1 (permalink)  
Old July 1st, 2005, 12:09 AM
Friend of Wrox
Join Date: Sep 2003
Location: , , .
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get datagrid selected index pl help me


My datagrid conails Dropdownlist ,lbel and some BoundColumns.
When i change the item from Dropdownlist i want to display the selected item value in the label template column of datagrid.Here i am not getting how to get the selected row index of datagrid.

Pl help me.

public void DD_SelectedIndexChanged(object sender, System.EventArgs e)
            System.Web.UI.WebControls.DropDownList ed ;
            ed = (System.Web.UI.WebControls.DropDownList) sender ;
            string x=ed.SelectedItem.Text;
            string y=getsomval(x);

            DataGrid1.Items[???].Cells[2].Text =y;

//Here i need to get the DataGridselected Index (means datagrid current row)


<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 128px"
                runat="server" Width="400px" Height="264px" OnSortCommand="DataGrid1_SortCommand" AllowSorting="True">
                        <asp:BoundColumn DataField="Address" SortExpression="address" ReadOnly="True" HeaderText="Address"></asp:BoundColumn>
                    <asp:TemplateColumn HeaderText="compname" HeaderStyle-Font-Size="10px" ItemStyle-Font-Size="8">
                            <asp:DropDownList OnSelectedIndexChanged="DD_SelectedIndexChanged" AutoPostBack = True id = "DD" DataSource="<%# BindThecomp() %>" DataTextField="name" DataValueField="name" Runat =server />

                    <asp:TemplateColumn HeaderText="corval" HeaderStyle-Font-Size="10px" ItemStyle-Font-Size="8">
                            <asp:label text="" runat =server OnDataBinding ="bindid" />


  #2 (permalink)  
Old July 1st, 2005, 08:03 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

The easiest way I've found to do this is to walk up the .Parent(s) of the objects. Eventually you'll get up to the the DataGridItem where you can access .ItemIndex.

For controls in a column of a a data grid, the walk up the control should look like this:

control.Parent = the cell the control's in
cell.Parent = DataGridItem


Similar Threads
Thread Thread Starter Forum Replies Last Post
index by table in pl/sql vipin1982 All Other Wrox Books 1 October 1st, 2008 12:19 PM
find the selected index of the dropdownlist suneet.pant ASP.NET 2.0 Basics 0 May 22nd, 2008 03:45 AM
DropDownList Selected Index = -1?? dorothee ASP.NET 1.0 and 1.1 Basics 4 June 11th, 2004 03:08 AM

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