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

DataGrid, ItemTemplate, ItemDataBound 1

Status
Not open for further replies.

tgreer

Programmer
Oct 4, 2002
1,781
US
I have a typical DataGrid with a TemplateColumn. The template column contains lots of "stuff": images, linkbuttons, labels, etc.

A DataSet is bound to the DataGrid.

I'm using the <%#DataBinder.Eval(Container,&quot;sqlField&quot;)%> syntax to bind values here and there.

In my ItemDataBound event handler, I'm looking at values in the DataSet.

I want to change the value of a label within the DataGrid TemplateColumn based on a value in the DataSet.

The event is firing right, I've got down to an IF statement for the DataSet value, all I need to do is add code to say &quot;now change such and such&quot;. I don't know how to refer to controls in the column/cell/whatever.

I hope that was clear, if not I can post code on Monday.

Thomas D. Greer
 
in the ItemDataBound event....

For a textbox...
((TextBox)e.Item.FindControl(&quot;whatever&quot;)).Text=&quot;your value&quot;;

works the same way for other controls....just cast to the proper control and you can set it's properties as you normally would. Hope this helps
 
The &quot;whatever&quot; in your code snippet is what, the control name? ID? How can that be determined, since these controls are named dynamically as the datagrid is filled?

Thomas D. Greer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top