Hello, I used a DataList to show some data from my database. I have an edit button that allows me to update the field but when I click on edit it takes me to the beginning of the page. It would be a whole better if after clicking edit, the page would stay at the same spot. I tried using an anchor but have not been able to make it work.
Here is the datalist code
CODE
<asp:DataList ID="SoftwareList" Font-Size="Small"
AlternatingItemStyle-BackColor="Azure"
HeaderStyle-BackColor="PowderBlue"
RepeatDirection="Vertical"
RepeatLayout="Table" SelectedItemStyle-BackColor="Yellow"
OnEditCommand="SoftwareList_EditCommand"
OnCancelCommand="SoftwareList_CancelCommand"
runat="server" onitemcommand="SoftwareList_ItemCommand"
EditItemStyle-BackColor="Yellow"
onupdatecommand="SoftwareList_UpdateCommand">
<HeaderTemplate>
Software Name
</HeaderTemplate>
<ItemTemplate>
<a id='Modify.aspx#<%# DataBinder.Eval(Container.DataItem,"softwareName")%>'></a>
<%# DataBinder.Eval(Container.DataItem,"softwareName")%>
<asp:LinkButton ID="button1" runat="server" Text="Edit" CommandName="edit"></asp:LinkButton>
</ItemTemplate>
<SelectedItemTemplate>
Software Name:
<br />
<%# DataBinder.Eval(Container.DataItem,"softwareName")%>
<br />
Path:
<%# DataBinder.Eval(Container.DataItem,"Exe_path")%>
<br />
</SelectedItemTemplate>
<EditItemTemplate>
Software:
<asp:Label ID="SoftwareNameLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"softwareName")%>' />
<asp:TextBox id="SoftwareNameTextBox" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"softwareName")%>' />
<br />
Path:
<asp:TextBox ID="PathTextBox" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Exe_Path")%>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" Text="Update" CommandName="update" />
<asp:LinkButton ID="CancelButton" runat="server" Text="Cancel" CommandName="cancel" />
</EditItemTemplate>
</asp:DataList>
CODE
protected void SoftwareList_EditCommand(object source, DataListCommandEventArgs e)
{
SoftwareList.EditItemIndex = (int)e.Item.ItemIndex;
}
I tried <a id="#'<%#DataBinder.Eval(Container.DataItem,"softwareName")%>' "></a> in the itemTemplate tags and then in the EditCommand method having a Response.Redirect("#" + nameOfSoftware) command to navigate to the part of the page I just clicked on. This did not work though because I am getting a Object reference not set to an instance of an object error. Any suggestions?