J
Jeff User
Hi
I tryed to solve this problem over in the framework.asp group, but
still am having trouble. Hope someone here can help.
using .net 1.1, VS 2003 and C#
I have an asp.DataGrid control with a Delete button on the end of each
row. I am unable to gain access to the event when the button is
clicked.
I don't fully understand how the click gets connected to the C# code,
which makes figuring this out difficult. If anyone can see my problem
or explain how this works so that maybe I can figure it out, I would
be most happy. I will also post complete code if anyone wants to see
it.
Here is what I do to create this grid and Delete button and then what
I end up with:
- Drag the grid onto the page in design view and name it
"dgAccessPrivs".
- Go to the properties window and through the Columns property, define
a few bound columns and then the Delete button column.
This produces the aspx code for the grid like this:
<aspataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px;
POSITION: absolute; TOP: 192px" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Grantor" ReadOnly="True"
HeaderText="Grantor"></asp:BoundColumn>
<asp:BoundColumn DataField="Grantee" ReadOnly="True"
HeaderText="Grantee"></asp:BoundColumn>
<asp:BoundColumn DataField="Object_Type" ReadOnly="True"
HeaderText="Object Type"></asp:BoundColumn>
<asp:BoundColumn DataField="Object_Name" ReadOnly="True"
HeaderText="Object Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Privilege_Type" ReadOnly="True"
HeaderText="Privilege"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
</aspataGrid>
Notice that no "OnDeleteCommand = ..."
or "OnItemCommand = ..." phrases are generated. I don't know if they
are required or not......?
Properties window for this grid shows
Enabled set to True
and
EnableViewState set to True.
Set my datasource and perfprm databind()
Then, while viewing the grid in design view, I go to properties
window, click the lightning bolt (events) and double click
"DeleteCommand" in the list. Got this information from VS/msdn help.
The following C# code is generated:
this.dgAccessPrivs.DeleteCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgAccessPrivs_DeleteCommand);
This is created in the initializeComponent procedure that runs every
time the form loads.
Q1) I take it this somehow binds the aspx datagrid event to the C#
code shown below?
The shell for the event procedure code is also generated.:
private void dgAccessPrivs_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{....}
Code placed in this procedure does not run. It never executes.
Never..
Q2) First of all, is this even the correct event? Should I have chosen
something else like OnItemCommand ? (that didnt work either)
I have also been suggested to use the OnItemCommand. Double clicking
this in the events window for the grid also produces code similar to
that shown above, but doesnt work.
Q3) (If this is relevant) what are all these OnItemCommand and
OnDeleteCommand phrases that can be placed in the html/asp code for
the grid??? Are they also required?
I have tryed it with them, without them, many combinations of all code
mentioned and shown above, but can never get the code to run in the
dgAccessPrivs_DeleteCommand(){} procedures.
Going on day 4
Thanks
Jeff
I tryed to solve this problem over in the framework.asp group, but
still am having trouble. Hope someone here can help.
using .net 1.1, VS 2003 and C#
I have an asp.DataGrid control with a Delete button on the end of each
row. I am unable to gain access to the event when the button is
clicked.
I don't fully understand how the click gets connected to the C# code,
which makes figuring this out difficult. If anyone can see my problem
or explain how this works so that maybe I can figure it out, I would
be most happy. I will also post complete code if anyone wants to see
it.
Here is what I do to create this grid and Delete button and then what
I end up with:
- Drag the grid onto the page in design view and name it
"dgAccessPrivs".
- Go to the properties window and through the Columns property, define
a few bound columns and then the Delete button column.
This produces the aspx code for the grid like this:
<aspataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px;
POSITION: absolute; TOP: 192px" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Grantor" ReadOnly="True"
HeaderText="Grantor"></asp:BoundColumn>
<asp:BoundColumn DataField="Grantee" ReadOnly="True"
HeaderText="Grantee"></asp:BoundColumn>
<asp:BoundColumn DataField="Object_Type" ReadOnly="True"
HeaderText="Object Type"></asp:BoundColumn>
<asp:BoundColumn DataField="Object_Name" ReadOnly="True"
HeaderText="Object Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Privilege_Type" ReadOnly="True"
HeaderText="Privilege"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
</aspataGrid>
Notice that no "OnDeleteCommand = ..."
or "OnItemCommand = ..." phrases are generated. I don't know if they
are required or not......?
Properties window for this grid shows
Enabled set to True
and
EnableViewState set to True.
Set my datasource and perfprm databind()
Then, while viewing the grid in design view, I go to properties
window, click the lightning bolt (events) and double click
"DeleteCommand" in the list. Got this information from VS/msdn help.
The following C# code is generated:
this.dgAccessPrivs.DeleteCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgAccessPrivs_DeleteCommand);
This is created in the initializeComponent procedure that runs every
time the form loads.
Q1) I take it this somehow binds the aspx datagrid event to the C#
code shown below?
The shell for the event procedure code is also generated.:
private void dgAccessPrivs_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{....}
Code placed in this procedure does not run. It never executes.
Never..
Q2) First of all, is this even the correct event? Should I have chosen
something else like OnItemCommand ? (that didnt work either)
I have also been suggested to use the OnItemCommand. Double clicking
this in the events window for the grid also produces code similar to
that shown above, but doesnt work.
Q3) (If this is relevant) what are all these OnItemCommand and
OnDeleteCommand phrases that can be placed in the html/asp code for
the grid??? Are they also required?
I have tryed it with them, without them, many combinations of all code
mentioned and shown above, but can never get the code to run in the
dgAccessPrivs_DeleteCommand(){} procedures.
Going on day 4
Thanks
Jeff