Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #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" />


Reply With Quote
  #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

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 05:57 PM.

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