Find a column by name

E

Eagle

How do I find a column in a grid by the name of the column? I find I'm
constantly having to change the cell numbers because the order of the
columns in the grid changes. Thanks.
 
T

Teemu Keiski

Hi,

columns do not have a name, if you mean a Datagrid. Simple way is to use
Labels or LiteralControls in the columns (in a template), which you could
locate with FindControl and set/get text properties respectively. That way
you wouldn't depend on the order of the columns.
 
E

Eagle

Thanks! I did a
Dim MyValue2 as String = CType(e.Item.FindControl("Year"), TextBox).Text

So I can now find the control and get the value of the control, but how do I
find its CellIndex and Control Index number? I have to pass the indexes
into another procedure that creates a dropdownlist:
Dim ddl As DropDownList =
CType(e.Item.Cells(CellIndex).Controls(ControlIndex), DropDownList)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top