Forum Moderators: open
Any help, links to articles, etc. would be very welcome.
Thanks much,
Ross
and then you can reference it in your code using
Private Sub DataGrid_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.UpdateCommand
dim sUserId as string=DataGrid.DataKeys(CInt(e.Item.ItemIndex))
'do update where sUser....
End Sub
I hope it will help
It appears my update event is not firing for some reason. Here is the datalist definition:
<asp:datalist id="dlTickets" datakeyfield="id" runat="server" width="60%" repeatcolumns="1" itemstyle-font-size="10pt" OnItemDataBound="DataGrid_ItemCreated">
Here is the button definition:
<itemtemplate>
<asp:button Text="Close" CommandName="Update" id="btnClose" runat="server" visible="true"></asp:button>
</itemtemplate>
And here is the code that doesn't run:
Sub dlTickets_Update(ByVal Sender As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlTickets.UpdateCommand
Response.Write("Achoo!")
End Sub
Any ideas? What am I missing?
Thanks again!
Sub MyGrid_Update(sender As Object, e As DataGridCommandEventArgs)
response.write("Hello World")
End Sub
make sure to add OnUpdateComand event to your datagrid
OnUpdateCommand="MyGrid_Update"
I added the onUpdateCommand event after my last post, obviously to no avail since I'm still pulling my hair out here... and I have frightfully little to spare ;)
There is a generated line at the top of the html page that says AutoEventWireup="false". I'm assuming that's OK.
Also, I added this to the top of the code behind class since the editor didn't insert it when I added my button to the itemtemplate list:
Protected WithEvents btnClose As System.Web.UI.WebControls.Button
Not sure where to go from here, I may abandon the button and attempt a linkbutton, but I fear I'll have the same issue. Ooops there goes another hair...
Private Sub ShoppingCart_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ShoppingCart.UpdateCommand
'hello world
End Sub
and
<itemtemplate>
<asp:button Text="Close" CommandName="Update" id="btnClose" runat="server" visible="true"></asp:button>
</itemtemplate>
replace with
<asp:ButtonColumn Text="Close" HeaderText="Button Text" CommandName="Update" />
Sub dlTickets_UpdateCommand(ByVal Sender As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlTickets.UpdateCommand
Response.Write("hello world")
End Sub<asp:datalist id="dlTickets" runat="server" width="60%" repeatcolumns="1" itemstyle-font-size="10pt" OnItemDataBound="DataGrid_ItemCreated" datakeyfield="id">
<itemstyle font-size="10pt"></itemstyle>
<itemtemplate>
<asp:button Text="Close" CommandName="update" id="btnClose" runat="server" visible="true">
</asp:button><br>
</itemtemplate>
</asp:datalist>
Also tried with this in datalist definition
OnUpdateCommand="dlTickets_UpdateCommand"
I'm obviously missing something, but what? Well at least I'll be saving on barbering ;)
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
dlTickets.DataSource = CreateDataSource()
dlTickets.DataBind()
End If
End Sub
Private Sub dlTickets_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlTickets.DeleteCommand
Dim sID As String = dlTickets.DataKeys(e.Item.ItemIndex)
Response.Write(sID)
End Sub
Function CreateDataSource() As ICollection
Dim dt As DataTable
Dim dr As DataRow
Dim i As Integer
'create a DataTable
dt = New DataTable()
dt.Columns.Add(New DataColumn("id", GetType(Integer)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
'Make some rows and put some sample data in
For i = 1 To 9
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
'add the row to the datatable
dt.Rows.Add(dr)
Next
'return a DataView to the DataTable
CreateDataSource = New DataView(dt)
End Function
Private Sub dlTickets_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlTickets.ItemCreated
End Sub
End Class