Вопрос

I have a Repeater which contains Eval commands and a Button (Which I can't access) I would like to access this button and when clicked insert one of the Eval commands (Eg. Car Model) into a listbox I have on the same page.

<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />  


<asp:Repeater ID="Repeater2" runat="server" DataSourceID="AccessDataSource1" DataMember="DefaultView" OnItemDataBound="Repeater2_ItemDataBound">
    <ItemTemplate>
        <div>     
            <p><img src="carImages/<%#Eval("Artwork")%>" /></div>
            <div class="col-xs-4">    
            <h4><%# Eval("Make")%> (<%# Eval("Year") %>)</h4>
            <p><%# Eval("Model")%></p>
            <p><%# Eval("Colour")%></p>
            <p><%# Eval("Type")%></p>
        <div>
            <asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />  
            </div>
          </a>
            </div>
    </ItemTemplate>     

Это было полезно?

Решение

Just add your oncommand argument to the repeated button

<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' OnCommand="CommandBtn_Click" Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />

you can grab the eval in the behind code

void CommandBtn_Click(Object sender, CommandEventArgs e){
    var command = e.CommandArgument;
    // Do whatever with it here
}

That will get the evaluated model

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top