Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting DataGrid without knowing names of fields 1

Status
Not open for further replies.

ChrisBrunner

Programmer
Dec 16, 2004
7
US
Hi all,
I have a DataGrid that's never populated using the same SQL query. Since the column (field) names are usually different, I don't know of a way to create a SortView based on a member of my dataset's DefaultView. Is it still possible to sort this DataGrid? If so, how?

Thanks in advance
 
Could you have your sort command recognize the HeaderName that you clicked on to sort..then make sure your column names are the same...then send your query that value...

dlc
 
You can grab the column names in the ItemDataBound event and take it from there:
Code:
private void dg1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			ListItemType itemType = (ListItemType)e.Item.ItemType;
			if(itemType == ListItemType.Header)
			{
				for(int i = 0; i < dg1.Columns.Count; i++)
				{
					Response.Write("Column Text = " + dg1.Columns[i].HeaderText.ToString() + "<br>");
				}

			}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top