Actually, I am thinking about giving up trying to create the DataGrid
Dynamically. The template seems more trouble than it is worth. I can
create the template fine, but you have to use an ascx file to get it to
work.
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11*********************@y42g2000hsy.googlegro ups.com...
On Aug 30, 12:02 am, "tshad" <t...@home.comwrote:
>If I added:
OnClick="Resume_Submit"
I get the error:
'resume_submit' is not a member of 'ASP.testTemplateColumn2_ascx'.
You should create it, I guess
The problem is that the ascx file is nothing more than the Template code
inside the TemplateColumn tags:
<%@ Language="VB" %>
<asp:LinkButton id="ResumeDate"
text="test"
visible="true"
width="80px"
runat="server"/>
There is no code here.
This works fine but does nothing, really.
>
>>
So I tried to do it where I create the TemplateColumn (the line that is
commented out). If I uncomment it I get:
'OnClick' is not a member of 'System.Web.UI.WebControls.TemplateColumn'.
It's true, there is no 'OnClick' method
Right. For the TemplateColumn there isn't one and the problem is trying to
get access to the LinkButton I just created.
>
>How would I access it from the TemplateColumn to set it?
First of all you should decide what you need to have. "OnClick" for
the LinkButton control is not the same with "OnClick" for a whole
column of the grid(?) control. When you want to load control with
Page.LoadTemplate then you shoud assign the onclick method in
testTEmplateColumn2.ascx.
Can't assign it in the .ascx file.
Espisito mentions that you can't do this. You need to get to the access to
the LinkButton directly. You have to grab it as it is being created on the
ItemCreated event. The problem is you can't do:
DataGrid1.onItemCreated = "ItemCreated"
This will give you an error:
'System.Web.UI.WebControls.DataGrid.Protected Overridable Sub
OnItemCreated(e As System.Web.UI.WebControls.DataGridItemEventArgs)' is not
accessible in this context
Rock in a hard place problem.
I realized looking at Espisitos article, he was creating the DataGrid in the
..aspx page and then adding the Controls later. So his article didn't really
help me much.
He also doesn't mention that you need to create the DataGrid in the
Page_Init event because on the PostBack it won't be there. Apparently, the
viewstate keeps the data for the columns but not the columns themselves, so
you have to recreate columns before the page gets the data from the
viewstate to populate the DataGrid. If you don't you have nothing where the
DataGrid is supposed to be.
The problem is that I am building the datagrid from my Sql Statement that I
fill my DataTable with and using the DataTables Columns to build the
DataGrids columns. So to recreate the DataGrid I would need to re-read my
data from Sql on each Post Back. I think it is probably easier to just
build the DataGrid with all its columns and TemplateColumns and then just
move the columns where I want in the Page_Init event.
Been an experiance.
Thanks,
Tom