0

I have a gridview with a template column:

<asp:UpdatePanel runat="server">  
 <ContentTemplate>  
  <asp:GridView ID="gridDay" runat="server" SkinID="gridviewSkinLight" AutoGenerateColumns="False" DataSourceID="DSAppointmentForDay">  
   <Columns>  
    <asp:BoundField DataField="TimeValue" HeaderText="" InsertVisible="False" ReadOnly="True" SortExpression="TimeValue" />  
    <asp:TemplateField HeaderText=" ">  
     <ItemStyle HorizontalAlign="Left" />  
    </asp:TemplateField>  
   </Columns>  
  </asp:GridView>  
 </ContentTemplate>  
 <Triggers>  
  <asp:AsyncPostBackTrigger ControlID="gridDay" />  
 </Triggers>  
</asp:UpdatePanel>  

On the RowDataBound, I create buttons in the cell if data is found that matches a condition:

Dim cmdNew As New Button  
cmdNew.ID = "E" & dr("pkAppointment") & "|" & dr("ApptTopic")  
AddHandler cmdNew.Click, AddressOf mySub  
cmdNew.Text = dr("ApptTopic") & " >> " & dr("ApptLocation")  
cmdNew.ToolTip = "Topic: " & dr("ApptTopic") & vbLf &
                 "Location: " & dr("ApptLocation")  
e.Row.Cells(1).Controls.Add(cmdNew)  

Up to here, everything is great. The buttons are created in the right cell with all their bells and whistles.

The routine that the button should call is:

Private Sub mySub(sender As System.Object, e As System.EventArgs)
    Try
        Dim btn As Button = DirectCast(sender, Button)
        MsgBox(btn.Text)

    Catch ex As Exception

    End Try
End Sub  

The moment I click on the button, the page does a refresh, all the created buttons disappear and mySub is not called.

Am I missing something?

4

1 に答える 1