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:
<asp:DataGrid 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>
</asp:DataGrid>
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.DataGridCommandEventHand ler(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 4 1979
Jeff User wrote: 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:
<asp:DataGrid 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> </asp:DataGrid>
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.DataGridCommandEventHand ler(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..
[This code is running only when the DeleteCommand is raised, are you
sure it is the case .] 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.
[ The function name change doesn't make any difference. You want to make
sure the function is correctly hooked to the event handler].
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.
[ I don't think you have hooked up the right event handler with the
function, this.dgAccessPrivs.DeleteCommand+, where did you find this
DeleteCommand?] Going on day 4 Thanks Jeff
John [This code is running only when the DeleteCommand is raised, are you sure it is the case .]
No, I am not sure of anything at this point. That is one my problems
is that I am not sure what event I am actually supposed to be trying
to catch and/or if I am supposed to declare it somewhere....
[ I don't think you have hooked up the right event handler with the function,
I think you are correct in that something is not connected as it
should be.
this.dgAccessPrivs.DeleteCommand+, where did you find this DeleteCommand?]
In DataGrid Properties window->Events list. I double clicked it
(DeleteCommand). From what I read in online help for the
"DataGrid.DeleteCommand Event " I thought that was the name of the
event to go after. But then the example code went and did it
differently (OnItemCommand="ItemsGrid_Command")
so then I was totally confused anyway.
So, how do I know the name of the event that I am trying to catch
into?
and then, is that line: this.dgAccessPrivs.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgAccessPrivs_DeleteCommand);
the line that actually makes the connection between the event and the
procedure?
Thanks
Jeff
On Sat, 04 Feb 2006 23:58:55 -0500, John Sun <js***********@gmail.com>
wrote:
Jeff User wrote: 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:
<asp:DataGrid 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> </asp:DataGrid>
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.DataGridCommandEventHand ler(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..
[This code is running only when the DeleteCommand is raised, are you sure it is the case .] 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. [ The function name change doesn't make any difference. You want to make sure the function is correctly hooked to the event handler].
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.
[ I don't think you have hooked up the right event handler with the function, this.dgAccessPrivs.DeleteCommand+, where did you find this DeleteCommand?] Going on day 4 Thanks Jeff
I checked : http://msdn.microsoft.com/library/de...mmandtopic.asp
Change this from
<asp:DataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px;
POSITION: absolute; TOP: 192px" runat="server"
AutoGenerateColumns="False">
to
<asp:DataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px;
POSITION: absolute; TOP: 192px" runat="server"
AutoGenerateColumns="False"
OnDeleteCommand="dgAccessPrivs_DeleteCommand">
Check to see whether it makes a difference.
HTH.
Jeff User wrote: John [This code is running only when the DeleteCommand is raised, are you sure it is the case .]
No, I am not sure of anything at this point. That is one my problems is that I am not sure what event I am actually supposed to be trying to catch and/or if I am supposed to declare it somewhere....
[ I don't think you have hooked up the right event handler with the function, I think you are correct in that something is not connected as it should be.
this.dgAccessPrivs.DeleteCommand+, where did you find this DeleteCommand?] In DataGrid Properties window->Events list. I double clicked it (DeleteCommand). From what I read in online help for the "DataGrid.DeleteCommand Event " I thought that was the name of the event to go after. But then the example code went and did it differently (OnItemCommand="ItemsGrid_Command") so then I was totally confused anyway.
So, how do I know the name of the event that I am trying to catch into?
and then, is that line: this.dgAccessPrivs.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgAccessPrivs_DeleteCommand);
the line that actually makes the connection between the event and the procedure?
Thanks Jeff On Sat, 04 Feb 2006 23:58:55 -0500, John Sun <js***********@gmail.com> wrote:
Jeff User wrote: 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:
<asp:DataGrid 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> </asp:DataGrid>
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.DataGridCommandEventHand ler(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.. [This code is running only when the DeleteCommand is raised, are you sure it is the case .] 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. [ The function name change doesn't make any difference. You want to make sure the function is correctly hooked to the event handler].
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. [ I don't think you have hooked up the right event handler with the function, this.dgAccessPrivs.DeleteCommand+, where did you find this DeleteCommand?] Going on day 4 Thanks Jeff
Well, here is what I have learned.
First, I tryed as you suggested with no results. I had tryed this
before, but did so again and nothing.
So, I finally decide that maybe it works, but the code for some reason
never gets there. So
I went to my page_load method and tryed to skip everything I can. What
I found out is that if I skip the
dgAccessPrivs.DataBind();
line, the page_load procedure finishes AND THEN execution continues
into the event procedures. Ah ha!
So, of course I let it bind the first time so that the rows in the
grid are populated with a delete button on each. Then after clicking
the delete button, I break at the DataBind statement and then skip
around it. Now execution moves to the event procedures. Wala !
2 things to note here:
1) is what I learned, and
2) Still have to figure out why does it do this?
1) By defining the datagrid like this: <asp:DataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px; POSITION: absolute; TOP: 192px" runat="server" AutoGenerateColumns="False" OnDeleteCommand="dgAccessPrivs_DeleteCommand">
AND having a C# intitializeComponent() procedure entry like this:this.dgAccessPrivs.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgAccessPrivs_DeleteCommand);
the DeleteCommand event procedure runs twice!! (If I skip the
databinding to the grid).
Removing either one OR the other by itself will cause the event
procedure to run once (If I skip the databinding to the grid). So I
guess you can bind the event to the procedure by either declaring it
in the asp code OR
manually binding it in the C# code.
2) Now, I have to figure out, why , after binding the the dataset to
the grid, does the page_load procedure finish, but then THE EVENT CODE
NEVER RUNS.
?????
Thank you very much for your help
Jeff
On Sun, 05 Feb 2006 09:30:50 -0500, John Sun <js***********@gmail.com>
wrote:
I checked :
http://msdn.microsoft.com/library/de...mmandtopic.asp
Change this from <asp:DataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px; POSITION: absolute; TOP: 192px" runat="server" AutoGenerateColumns="False">
to
<asp:DataGrid id="dgAccessPrivs" style="Z-INDEX: 110; LEFT: 296px; POSITION: absolute; TOP: 192px" runat="server" AutoGenerateColumns="False" OnDeleteCommand="dgAccessPrivs_DeleteCommand">
Check to see whether it makes a difference.
HTH. Jeff User wrote: John [This code is running only when the DeleteCommand is raised, are you sure it is the case .]
No, I am not sure of anything at this point. That is one my problems is that I am not sure what event I am actually supposed to be trying to catch and/or if I am supposed to declare it somewhere....
[ I don't think you have hooked up the right event handler with the function, I think you are correct in that something is not connected as it should be.
this.dgAccessPrivs.DeleteCommand+, where did you find this DeleteCommand?] In DataGrid Properties window->Events list. I double clicked it (DeleteCommand). From what I read in online help for the "DataGrid.DeleteCommand Event " I thought that was the name of the event to go after. But then the example code went and did it differently (OnItemCommand="ItemsGrid_Command") so then I was totally confused anyway.
So, how do I know the name of the event that I am trying to catch into?
and then, is that line: this.dgAccessPrivs.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgAccessPrivs_DeleteCommand); the line that actually makes the connection between the event and the procedure?
Thanks Jeff On Sat, 04 Feb 2006 23:58:55 -0500, John Sun <js***********@gmail.com> wrote:
Jeff User wrote: 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:
<asp:DataGrid 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> </asp:DataGrid>
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.DataGridCommandEventHand ler(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.. [This code is running only when the DeleteCommand is raised, are you sure it is the case .] 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.
[ The function name change doesn't make any difference. You want to make sure the function is correctly hooked to the event handler].
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. [ I don't think you have hooked up the right event handler with the function, this.dgAccessPrivs.DeleteCommand+, where did you find this DeleteCommand?] Going on day 4 Thanks Jeff This discussion thread is closed Replies have been disabled for this discussion. Similar topics
7 posts
views
Thread by TT (Tom Tempelaere) |
last post: by
|
2 posts
views
Thread by pei_world |
last post: by
|
5 posts
views
Thread by John Richardson |
last post: by
|
8 posts
views
Thread by Brent Burkart |
last post: by
|
2 posts
views
Thread by andla |
last post: by
|
2 posts
views
Thread by Deepesh |
last post: by
|
1 post
views
Thread by mike |
last post: by
|
5 posts
views
Thread by Jeff User |
last post: by
|
9 posts
views
Thread by rn5a |
last post: by
| | | | | | | | | | |