Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Wanna-Be C# Superstar
Posted

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.

Wanna-Be C# Superstar
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...