Rickyc1
asked on
Have a datagrid question with edit update delete buttons
I'm trying to get a grid running that gives the user the ability to edit, delete and save changes to the row, basic if you ask me.
Well I noticed that I have to click twice on the edit button for it to go to editcommand event. The item command event fires on a single click but doesnt call the edit command on the first click. Why???
Here is the html and the code behind. I would like to use templates cause I feel I have more control over the look and feel of the control. But at this point I don't care just want to get it running.
Private Sub dgParentCat_ItemCommand(By Val source As Object, ByVal e As System.Web.UI.WebControls. DataGridCo mmandEvent Args) Handles dgParentCat.ItemCommand
dgParentCat.EditItemIndex = e.Item.ItemIndex
End Sub
End Class
Private Sub dgParentCat_EditCommand(By Val source As Object, ByVal e As System.Web.UI.WebControls. DataGridCo mmandEvent Args) Handles dgParentCat.EditCommand
dgParentCat.EditItemIndex = e.Item.ItemIndex
End Sub
<asp:datagrid id="dgParentCat" runat="server" AutoGenerateColumns="False " AllowSorting="True"
PageSize="5" Width="446px" CssClass="TextBox1">
<Columns>
<asp:TemplateColumn HeaderText="Parent Category">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentCategory") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ParentCategory") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Edit">
<ItemTemplate>
<asp:Button id="dgedit" runat="server" CssClass="Button1" CommandArgument="EditParen tBT" CommandName="EditButton"
Text="Edit"></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button id="btnSave" runat="server" CssClass="Button1" CommandArgument="SaveParen tBT" CommandName="SaveButton"
Text="Save"></asp:Button>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete"></asp: TemplateCo lumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:Edit CommandCol umn>
</Columns>
</asp:datagrid>
Well I noticed that I have to click twice on the edit button for it to go to editcommand event. The item command event fires on a single click but doesnt call the edit command on the first click. Why???
Here is the html and the code behind. I would like to use templates cause I feel I have more control over the look and feel of the control. But at this point I don't care just want to get it running.
Private Sub dgParentCat_ItemCommand(By
dgParentCat.EditItemIndex = e.Item.ItemIndex
End Sub
End Class
Private Sub dgParentCat_EditCommand(By
dgParentCat.EditItemIndex = e.Item.ItemIndex
End Sub
<asp:datagrid id="dgParentCat" runat="server" AutoGenerateColumns="False
PageSize="5" Width="446px" CssClass="TextBox1">
<Columns>
<asp:TemplateColumn HeaderText="Parent Category">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container,
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container,
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Edit">
<ItemTemplate>
<asp:Button id="dgedit" runat="server" CssClass="Button1" CommandArgument="EditParen
Text="Edit"></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button id="btnSave" runat="server" CssClass="Button1" CommandArgument="SaveParen
Text="Save"></asp:Button>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete"></asp:
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:Edit
</Columns>
</asp:datagrid>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think you'll want to rebind the datagrid in each of those subs. Probably you should create a sub for binding the grid, then just call it in the page load and the ItemCommand, EditCommand, etc subs.
Private Sub dgParentCat_ItemCommand(By Val source As Object, ByVal e As System.Web.UI.WebControls. DataGridCo mmandEvent Args) Handles dgParentCat.ItemCommand
dgParentCat.EditItemIndex = e.Item.ItemIndex
BindDataGrid()
End Sub
Private Sub dgParentCat_ItemCommand(By
dgParentCat.EditItemIndex = e.Item.ItemIndex
BindDataGrid()
End Sub
ASKER
If Page.IsPostBack Then
Else
Dim ds As DataSet = SitePop.GetPictureMenuTB()
With Me.dgParentCat
.DataSource = ds.Tables(0)
.DataKeyField = "id"
.DataBind()
End With
End If