0

My question is this: what asp.net control do I have to use to generate a list of buttons with the text from database and with the action a link passing the ID of the object listed (id also from database)??

1
  • 1
    Use asp.net repeater to create UL, give it an id and get its reference in code behind. In your code behind create LinkButtons dynamically and append them to the UL. Commented Feb 14, 2013 at 17:48

2 Answers 2

2

What solved my problem was this incredible simple noobish solution:

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"
                DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <asp:Button Style="margin-top: 20px;" ID="Button1" Font-Size="X-Large" BackColor="Blue" ForeColor="White" runat="server" Text='<%# Eval("Descrizione") %>'
                        PostBackUrl='<%# "~/Assemblaggio3.aspx?idCompCrit="+Eval("ID") %>' /><br />

Sign up to request clarification or add additional context in comments.

Comments

1

a datarepeater with a bunch of buttons with unique commandArgument and a common command Name should do it.

from the top of my head :

<asp:Repeater runat="server">
  <ItemTemplate>
      <asp:Button id="<%# DataBinder.Eval(Container.DataItem, "someuniquecounter") %>"
           Text="<%# DataBinder.Eval(Container.DataItem, "columnContainingTextToDisplayToUser") %>"
           CommandName="CommonCommandName"
           CommandArgument="<%# DataBinder.Eval(Container.DataItem, "IdToPassToTheCommandEventHandler%>")"
           OnCommand="CommandBtn_Click" 
           runat="server"/>
  </ItemTemplate>
  <SeparatorTemplate>
    <br>
  </SeparatorTemplate>
</asp:Repeater>

in your command handler, you could first test if the command name is correct (you could have many depending on the action you want to accomplish), then get the command argument (the id) to pass to the correct method.

void CommandBtn_Click(Object sender, CommandEventArgs e) 
      {

         if((string.Compare(e.CommandName, "yourCommandName", false)==0)
         {
               YourMethodAcceptingTheIdAsParameter((int)e.CommandArgument);            
         }
      }

1 Comment

it gives me "id is not a valid identifier "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.