flann Posted August 23, 2005 Posted August 23, 2005 I have a datagrid and I'm trying to put in the edit command. The edit event works, it opens up the current record to edit, but when I click on the update button or cancel button, those events don't fire. Is there a step that I'm missing that would make these fire? Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
kahlua001 Posted August 23, 2005 Posted August 23, 2005 You need to wire up the UpdateCommand, CancelCommand, and DeleteCommand. Quote
flann Posted August 23, 2005 Author Posted August 23, 2005 How? I'm sorry I'm pretty new to this, and the books I have don't mention any "wiring up". Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
kahlua001 Posted August 23, 2005 Posted August 23, 2005 This is assuming you have an EditCommandColumn in your datagrid, each link button will trigger one of these subs. In each sub you get the key field you specify in your datagrid but using the ItemIndex. Private Sub Datagrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Datagrid1.CancelCommand 'Cancel command Datagrid1.EditItemIndex = -1 End Sub Private Sub Datagrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Datagrid1.UpdateCommand 'Update command Dim ProductID As Integer = Datagrid1.DataKeys(e.Item.ItemIndex) End Sub Private Sub Datagrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Datagrid1.DeleteCommand 'Delete command Dim ProductID As Integer = Datagrid1.DataKeys(e.Item.ItemIndex) End Sub Quote
flann Posted August 23, 2005 Author Posted August 23, 2005 yeah, I have all that. What is happening now is that when I click on edit, it goes to the edit event just fine. The problem is when I hit the update button, it goes through my page_load event, then my edit event, but not my update event. Any ideas? Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
flann Posted August 23, 2005 Author Posted August 23, 2005 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SqlDataAdapter1.SelectCommand.Parameters("@LeadID").Value = intLeadid SqlDataAdapter1.Fill(DsNegotiable1) DataGrid1.DataBind() End Sub Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex DataGrid1.DataBind() End Sub Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand SqlDataAdapter1.Update(DsNegotiable1) DsNegotiable1.Clear() DataGrid1.DataBind() End Sub Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
kahlua001 Posted August 23, 2005 Posted August 23, 2005 Do you need to load your databind in your page_load every time? Check for IsPostBack first, also, how do you know its not getting to your Updatecommand, are you doing anytype of debug message to see if it gets there? Quote
flann Posted August 23, 2005 Author Posted August 23, 2005 I have tried the If not ispostback then do my page load stuff. It doesn't reload my datagrid on the second trip. I debug by walking through every step that the program is taking for that page, it is never getting to the update or cancel events. Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
Hyuga Posted August 24, 2005 Posted August 24, 2005 Can you post the HTML code of your DataGrid, please? Maybe it will help. Quote
flann Posted August 24, 2005 Author Posted August 24, 2005 <asp:datagrid id=DataGrid1 runat="server" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical" DataSource="<%# DsNegotiable1 %>" AutoGenerateColumns="False" DataMember="UnsecuredDebts"> <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle> <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle> <ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle> <FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle> <Columns> <asp:BoundColumn DataField="CreditorName" SortExpression="CreditorName"></asp:BoundColumn> <asp:BoundColumn DataField="Code" SortExpression="Code" HeaderText="Code"></asp:BoundColumn> <asp:BoundColumn DataField="UnsecuredBalOwed" SortExpression="UnsecuredBalOwed" HeaderText="UnsecuredBalOwed"></asp:BoundColumn> <asp:BoundColumn DataField="UnsecuredPctRate" SortExpression="UnsecuredPctRate" HeaderText="UnsecuredPctRate"></asp:BoundColumn> <asp:BoundColumn DataField="UnsecuredLastPymtDate" SortExpression="UnsecuredLastPymtDate" HeaderText="UnsecuredLastPymtDate"></asp:BoundColumn> <asp:BoundColumn DataField="UnsecuredMinMoPymt" SortExpression="UnsecuredMinMoPymt" HeaderText="UnsecuredMinMoPymt"></asp:BoundColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn> <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> </Columns> <PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle> </asp:datagrid> Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
Hyuga Posted August 24, 2005 Posted August 24, 2005 ¿Don't you have to add this to your datagrid definition? <asp:datagrid id=DataGrid1 runat="server" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical" DataSource="<%# DsNegotiable1 %>" AutoGenerateColumns="False" DataMember="UnsecuredDebts" OnUpdateCommand="DataGrid1_UpdateCommand"> And OnCancelCommand, etc, etc..... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.