Datagrid with dynamic columns does not fire SelectedIndexChanged

T

tafpin

I have an application with a datagrid. In the IDE I have 2 template
columns. The first has an image button and the second contains a link
button.

According to the results that I get back I must add more columns to the
datagrid.

This is a sample of how I am adding these colums:

templateColumn = New TemplateColumn
templateColumn.HeaderText = "Number"
templateColumn.SortExpression = "112"
templateItem = New columnTemplate
templateItem.ColumnName = "Number"
templateColumn.ItemTemplate = templateItem
dgResults.Columns.Add(templateColumn)
CheckSortHeader(templateColumn)

AddHandler dgResults.SelectedIndexChanged, AddressOf
dgResults_SelectedIndexChanged

Once I bind the datagrid and get my result set back I see the datagrid
with all my values. Every field has a __doPostBack event associated to
it. If I understand correctly, ASP.NET automatically generates this
code and I cannot modify it.

If I click on one of the first 2 columns which were template columns in
the IDE, I see the Page_Load fire, then the datagrid's
SelectedIndexChanged followed by the Page_PreRender event. THis works
fine.

My problem is that if I click on one of the columns that I generated
dynamically The Page_Load will fire and then the Page_PreRender event.
The datagrid's SelectedIndexChanged does NOT fire.

I have tried the AddHandler to wire the SelectedIndexChanged event.

I am trying to understand why all of these are hotlinked but they are
not all behaving the same. I need to get the SelectedIndexChanged from
the dynamic columns.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top