VBAHole22 Posted January 11, 2006 Posted January 11, 2006 I have: this.myGrid.Items[e.Item.ItemIndex].Cells[4].Text and it works great as long as I don't add a column in before this one. If I do then this is off by one. Is there a way to do this by name. I am using a datagrid, asp.net 1.1 The items don't have ids so how would I get a hold of the correct one. I want to get a handle on a bound column at the selected index. Quote Wanna-Be C# Superstar
bri189a Posted January 15, 2006 Posted January 15, 2006 Instead of using 4 you could use a variable. or Instead on text in the cell you could have a label, give it an id then use FindControl. Quote
VBAHole22 Posted January 16, 2006 Author Posted January 16, 2006 Humm. not exactly what I had in mind. What do you mean by a variable? I guess without an id there really is no way to reference that cell without a digit. There has to be a way. Quote Wanna-Be C# Superstar
bri189a Posted January 17, 2006 Posted January 17, 2006 Well for instance in one application I've worked on a certain user control which had a datagrid was consumed by several pages. This datagrid had the same 8 columns of data for all the pages except for 1 which only had 7 of the 8 columns. The order of the columns was always the same, but processing had in column 2 that were dependant on columns 5 and 7 in all of the pages except for one, where because of that missing column it was columns 4 and 6. So in the control we had a property called ColumnOffset which looked something like so: Public ReadOnly Property ColumnOffset As Integer 'This is more psuedo code than anything If Me.Page.HasSpecialItem Then Return 0 Else Return 1 End If End Property Then in the OnItemDataBound event we had something similiar to: e.Item.Cells(0).Text = SomeGenericFunction(e.Item.Cells(5 - Me.ColumnOffset), e.Item.Cells(7 - Me.ColumnOffset)) This SomeGenericFunction would evalute the content of the cells and return necessary text, but the point is that by using this ColumnOffset variable, regardless of number of columns shown we were able to get the information we were looking for. Now this might be exactly what you need, but it's the kind of 'variable' type of thinking that I was eluding to. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.