i want to get the index value from selected rows of data grid..
how do i get it? can anyone explain...

Recommended Answers

All 4 Replies

int index = DataGrid1.SelectedIdex;

i got index value -1 for all rows..

In the aspx page DataGrid markup :

<asp:DataGrid id="DataGrid1" OnItemCommand="DataGrid1_ItemCommand" ...etc.

in the aspx.cs

protected void DataGrid1_ItemCommand(object sender, DataGridCommandEventArgs e)
{
    int index = e.Item.ItemIndex;
}

gurusamy (in PM to me)
i tried that too..
Whether i have to set any property for data grid..
bcoz i didn't get any event for data grid like ItemsIndex..

Have you wired up the event handler ?, if you're not using the designer but handcoding you have to add the handler delegates in the Web Form Designer generated code region of the aspx.cs file (If you're using Framework 1.1) See near the bottom of this snippet in the InitializeComponent method.

#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.DataGrid1.ItemCommand += new DataGridCommandEventHandler(DataGrid1_ItemCommand);
			
		}
		#endregion
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.