-1

I am populating a repeater on my asp.net web page (pop up) from a stored procedure call. I have a column where I need to build the hyperlink based on the values dynamically that calls an inquiry back to my original web form. However, the trouble I am having is that when I click on the link, I need to also retrieve some other data and insert this data into the viewstate.

The "GetListOfValues" function that I am calling obviously doesn't work the way I have this coded. Is there a way to accomplish this, and maybe even do it better than I am attempting to do it?

Here's my example:

Default.aspx

<asp:Repeater ID="rptReport" runat="server">
        <HeaderTemplate>
            <table>
                <tr>
                    <td>Name</td>
                    <td>ID</td>
                    <td>Value1</td>
                    <td>Value2</td>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
                <tr>
                    <td><%# DataBinder.Eval(Container.DataItem,"Name") %></td>
                    <td><%# DataBinder.Eval(Container.DataItem,"ID") %></td>
                    <td><%# DataBinder.Eval(Container.DataItem,"Value1") %></td>
                    <td><%# GetValueTwoLink(Eval("Name"),Eval("Value2") %></td>
                </tr>
        </ItemTemplate>
        <FooterTemplate>
                 <tr>
                     <%--This area holds totals for columns--%>
                 </tr>
            </table>
        </FooterTemplate>
    </asp:Repeater>

Default.aspx.cs

    protected string GetValueTwoLink(object name, object value2)
    {
        ViewState["ListOfValues"] = datalayer.GetListOfValues(name, value2);

        return string.Format(
            "<a href=\"#\" onlick=\"window.opener.ViewValues('{0}')\">{1}</a>",
            name,
            Convert.ToInt32(value2).ToString("d"));

    }

Any help would be appreciated!

LDWisdom
  • 111
  • 3
  • 16

1 Answers1

2

Not exactly sure what you are trying to do with that onclick... but you can do it on the code-front:

 <ItemTemplate>
     <tr>
         <td><%# Eval("Name") %></td>
         <td><%# Eval("ID") %></td>
         <td><%# Eval("Value1") %></td>
         <td>
             <a href="#" 
                 onclick="<%# String.Format("window.opener.ViewValues('{0}')", DataBinder.Eval(Container.DataItem,"Name")) %>">
                 <%# Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Value2")).ToString("d")%>
             </a>
         </td>
     </tr>
 </ItemTemplate>

Also, as you see, you can just use

<%# Eval("Name") %>

instead of

<%# DataBinder.Eval(Container.DataItem,"Name") %>

to just show data. You use the DataBinder.Eval when you need to do some manipulation, like in the 4th <td>.

MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
  • The problem I was having was setting that ViewState value when building the hyperlink, but I think I've figured that part out. What you laid out is definitely much cleaner than what I was doing, so I'll use that. Thank you very much for your help! – LDWisdom Mar 15 '13 at 00:54