Click here to Skip to main content
15,851,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help getting my events set up correctly. Here's what's going on.

I have a project where I don't know the number or location of GridViews until the user selects some options. I need to do this all on one asp page.

I have figured out that I can create and populate a GridView dynamically and add it to a placeholder's controls.
<asp:PlaceHolder ID="phTimeEntryDay" runat="server"></asp:PlaceHolder>

Protected WithEvents gvTimeEntry As GridView = New GridView()

I have added the edit and delete commands using code:
Dim cColumn As New CommandField

cColumn.ButtonType = ButtonType.Link
cColumn.CancelText = "Cancel"
cColumn.UpdateText = "Update"
cColumn.EditText = "Edit"
cColumn.DeleteText = "Delete"
cColumn.ShowEditButton = True
cColumn.ShowDeleteButton = True
cColumn.ShowCancelButton = True


This does set up the correct postback javascript events, but nothing happens when I click the links and the page is posted back.

In another project where I created the gridview at design-time, I can't find any code created to handle the events that I can copy to my project that does everything at run-time.
<asp:GridView ID="GridViewTimeSheet" runat="server" AllowSorting="True" AutoGenerateColumns="False"
    DataKeyNames="EmpPerNo,FromDate,ToDate,EntrySequence" DataSourceID="SqlDataSourcetimeEntry"
    ShowFooter="True" EmptyDataText="No Data Available.">
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

The only complete example I've found uses DataGrid in C# instead of GridView and there are enough differences in DataGrid and GridView that I can't adapt it completely.

Examples in VB or C# are fine if you have some.

Any help would be greatly appreciated.

Bryan Lee
aidin Tajadod 10-May-12 12:33pm    
I can not see anywhere in your code to define grids events. Try to attach the desiger events by using AddHandler.
ARBebopKid 10-May-12 13:02pm    
I'm lost at the disigner events. I can't figure out how the designer is handling events so I don't know what events to Add.

1 solution

I found this reference at msdn that gives me examples of the events I need to handle and how to handle them.[^]

Thank you, Aidin, for jogging my brain.
Share this answer
Maciej Los 10-May-12 13:44pm    
ARBebopKid, You are interesting man ;)
You ask a question and answer to yourself...
ARBebopKid 10-May-12 13:46pm    
I find I often can't figure out the answers until I've already asked for help. :)
aidin Tajadod 10-May-12 17:54pm    
You are very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900