J
Jim in Arizona
I'm don't know how I would get around this.
When working with a datalist control, there a specific built in commands
(OnEditCommand, OnCancelCommand, etc). These commands, when the datalist
control is made, refer to a subprocedure (eg:
OnUpdateCommand="MyUpdateProcedure").
When referring to a specific record that's written to the page by the
datalist object, it refers to the datakey (eg: <asp:datalist
datakeyfield="ID" ...>). Then whatever button I place into the
ItemTemplate, must refer to one of the OnWhateverCommand (edit, cancel,
update or delete), like so:
<asp:button ID="btnOne" CommandName="Update" runat="server" text="Update" />
Then, on the codepage, I would have:
Sub DL1_Update(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
Dim KeyField as String
KeyField = DL1.DataKeys(e.Item.ItemIndex)
'more code here to do the update
End Sub
Because of the DataListCOmmandEventArgs, I can create a string variable
and apply the keyfield of the record being displayed by the datalist
control. I would then used this in a sql statement, like so:
SQL = "UPDATE mytable SET name = 'John Smith' WHERE ID = " & KeyField
So, this all works fine, but I've run into a problem.
I wanted to put a button within the <ItemTemplate> of the datalist that
updates a record but, I don't know how. If I double click the button, I
get the click procedure of the button but I have no way to add a
reference to the DataKeyField of the datalist control.
I can't just do this:
Sub btnOne_Click(ByVal sender As Object, ByVal e As System.EventArgs,
ByVal r as DataListCommandEventArgs)
Dim KeyField as String
KeyField = DL1.DataKeys(r.Item.ItemIndex)
End Sub
I get a signature error when I do that.
So, how do I get around this?? Is there a way??
Thanks,
Jim
When working with a datalist control, there a specific built in commands
(OnEditCommand, OnCancelCommand, etc). These commands, when the datalist
control is made, refer to a subprocedure (eg:
OnUpdateCommand="MyUpdateProcedure").
When referring to a specific record that's written to the page by the
datalist object, it refers to the datakey (eg: <asp:datalist
datakeyfield="ID" ...>). Then whatever button I place into the
ItemTemplate, must refer to one of the OnWhateverCommand (edit, cancel,
update or delete), like so:
<asp:button ID="btnOne" CommandName="Update" runat="server" text="Update" />
Then, on the codepage, I would have:
Sub DL1_Update(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
Dim KeyField as String
KeyField = DL1.DataKeys(e.Item.ItemIndex)
'more code here to do the update
End Sub
Because of the DataListCOmmandEventArgs, I can create a string variable
and apply the keyfield of the record being displayed by the datalist
control. I would then used this in a sql statement, like so:
SQL = "UPDATE mytable SET name = 'John Smith' WHERE ID = " & KeyField
So, this all works fine, but I've run into a problem.
I wanted to put a button within the <ItemTemplate> of the datalist that
updates a record but, I don't know how. If I double click the button, I
get the click procedure of the button but I have no way to add a
reference to the DataKeyField of the datalist control.
I can't just do this:
Sub btnOne_Click(ByVal sender As Object, ByVal e As System.EventArgs,
ByVal r as DataListCommandEventArgs)
Dim KeyField as String
KeyField = DL1.DataKeys(r.Item.ItemIndex)
End Sub
I get a signature error when I do that.
So, how do I get around this?? Is there a way??
Thanks,
Jim