开发者

asp.net repeater with usercontrol - setting commandargument

开发者 https://www.devze.com 2023-01-23 06:34 出处:网络
I have the following repeater code: <asp:Repeater ID=\"repMain\" runat=\"server\" OnItemCommand=\"repMain_ItemCommand\" EnableViewState=\"false\">

I have the following repeater code:

 <asp:Repeater ID="repMain" runat="server" OnItemCommand="repMain_ItemCommand" EnableViewState="false">
    <ItemTemplate>
    <dmg:testcontrol runat="server" MyData=<%#Container.DataItem %>>


    </dmg:testcontrol>
    </ItemTemplate>
    </asp:Repeater>

The testcontrol usercontrol looks like:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="TestRepeater.TestControl" %>
<asp:Literal runat="server" ID="litMain" Text="<%#MyData.MyValue %>"></asp:Literal>
<asp:DropDownList runat="server" ID="dropdownMain"></asp:DropDownList>
<asp:Button runat="server" ID="btnMain" Text="Click Me" CommandName="Update" CommandArgument="<%#dropdownMain.SelectedValue%>"/>

Is it possible for me to send through the dropdownMain.SelectedValue as the CommandArgument?

Just now it is an empty string.

Thanks

Duncan

PS This is related to ASP.NET Repeater not binding after ItemCommand but I thought the two suffic开发者_如何学编程iently different to keep apart.


A bit old question but I just my self found the answer to this one.

CommandArgument="<%#dropdownMain.SelectedValue%>"

Needs to look like this instead with single quotes! All inline codes within a asp.net controls have to be done this way instead.

CommandArgument='<%#dropdownMain.SelectedValue%>'


Why not get the selected value, and use it inside the Command function ?

(why to try to send it as argument, from the moment you can get it inside the command called function and its the same)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号