ASP.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 307,163 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 1,529 people online right now. Registration is fast and FREE... Join Now!




Post back to a certain area of a page within a datalist

 

Post back to a certain area of a page within a datalist

isawpalmetto

25 Jun, 2009 - 01:12 PM
Post #1

New D.I.C Head
*

Joined: 2 Apr, 2009
Posts: 2

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?


User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: Post Back To A Certain Area Of A Page Within A Datalist

26 Jun, 2009 - 01:32 PM
Post #2

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,939



Thanked: 519 times
Dream Kudos: 11575
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Take a look at the MaintainScrollPositionOnPostBack Property
User is offlineProfile CardPM
+Quote Post

isawpalmetto

RE: Post Back To A Certain Area Of A Page Within A Datalist

29 Jun, 2009 - 06:02 AM
Post #3

New D.I.C Head
*

Joined: 2 Apr, 2009
Posts: 2

Thanks, that's what I was trying to find.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:06PM

Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month