Datalist edit items not working

T

tshad

I have a DataList that I have set up to allow editing. The edit button does
go to the subroutine defined by OnEditCommand. The problem is that it
doesn't change the fields to editing fields. The textbox doesn't show from
the edititemtemplate section. I don't get any errors.

Do I need to do something special to tell it to do this?

Here is the datalist:

********************************************************************************************
<asp:datalist id="DataList1"
runat="server"
Width="100%"
BorderWidth="0px"
OnEditCommand="DataListEdit"
OnUpdateCommand="DataListUpdate"
OnCancelCommand="DataListCancel"
footerstyle-horizontalalign="center"
CellPadding="0"
CellSpacing="0"
Border="0"
style="margin:0">
<AlternatingItemStyle cssClass=alternateRow ></AlternatingItemStyle>
<ItemTemplate>
<table border="0" width="100%" CellPadding="0" CellSpacing="0"
style="margin:0">
<tr>
<td width="100%">
<%# DataBinder.Eval(Container.DataItem, "Question") %>
</td>
<td width="30">
<asp:button Text="Edit" runat="server" CommandName="Edit" />
</td>
</tr>
</table>
</ItemTemplate>

<EditItemTemplate>
<table border="0" width="100%" CellPadding="0" CellSpacing="0"
style="margin:0">
<tr>
<td width="100%">
<asp:TextBox id="txtQuestion" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Question") %>' />
</td>
<td width="30">
<asp:button Text="Update" runat="server" CommandName="Update" />
<asp:button Text="Cancel" runat="server" CommandName="Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:datalist>
********************************************************************************************

Thanks,

Tom
 
T

tshad

I figured out what I did wrong here.

I forgot to do:

Dim oList as DataList = CType(S, DataList)
oList.EditItemIndex = e.Item.ItemIndex

But do I need to re-read the data and bind to the whole datalist again?

I have about 40 rows of data and want to change one row?

Thanks,

Tom
 
J

John Saunders

tshad said:
I figured out what I did wrong here.

I forgot to do:

Dim oList as DataList = CType(S, DataList)
oList.EditItemIndex = e.Item.ItemIndex

But do I need to re-read the data and bind to the whole datalist again?

I have about 40 rows of data and want to change one row?

You have to rebind the DataList. Depending on your data, that may mean you
have to re-read the data. If you've got it stored in Session or Cache, then
you wouldn't necessarily have to re-read it.

John Saunders
 
T

tshad

John Saunders said:
You have to rebind the DataList. Depending on your data, that may mean you
have to re-read the data. If you've got it stored in Session or Cache,
then you wouldn't necessarily have to re-read it.

If I have nested DataGrids in my DataList, I assume these would have to be
rebound also?

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top