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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value of a template column cell

Status
Not open for further replies.

TerryDad2

Programmer
Jul 10, 2002
29
0
0
US
I am trying to obtain the value in the datagrid from a template column.

e.Item.Cells(5).text returns a null value on template columns, but obtains the displayed text on a databoundcolumn.

What is the correct syntax for obtaining the displayed value in a template column?

Terry
 
Terry - you need to cast the contained control and obtain the value from that.

It will probably be something like

dim lblTheLabel as label = ctype(e.item.cells(5).controls(1), label)
and then your value is lblTheLabel.text

it's controls(1) because usually controls(0) is a literal control or something

Mark [openup]
 
Using that I get a
ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index
error.

This makes me think I am pulling from the wrong column, so I have moved to trying to get the value from cell 0 which I know is a template column. (dim lblTheLabel as label = ctype(e.item.cells(0).controls(1), label) and still get the same problem.

What are the controls that are in a tablecell?
 
Mark's post got me looking at what the control really is and I figured it out. The syntax is

CType(e.item.cells(5).controls(0), DataBoundLiteralControl).text

Terry
 
Try controls(0)

Also, you can put a breakpoint in (if you're using VS) and query the code in the command window until you get it right.

for example, when you're at the breakpoint, type this in the command window

? e.item.cells(0).controls(1)

it will output a whole load of stuff but by browsing it and changing the index for the cells and the controls, you will be able to eventually find the one you want.

If you are still having problems, post the HTML behind your datagrid

Mark [openup]
 
Yeah terry - I assumed that you'd accepted the default for a template column, which is a label in the item template and a textbox in the edit item template.
Glad you worked it out.
Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top