我有一个RadListView,在listview中我有一个asp.net linkbutton。我想动态设置linkbutton的PostBackUrl。如果我在listview的ItemDataBound事件中找到linkbutton控件,我可以实现这一点。但是,当我最终点击链接按钮时,没有触发listview ItemCommand事件。我需要触发itemCommand事件,以便我可以单击项目的datakeyvalue并将其设置为会话变量以传递到链接按钮的postbackurl页面,但是在页面加载时设置postbackurl导致linkbutton不会触发任何事件。
<telerik:RadListView ID="lstVwWebpageList" runat="server" EnableViewState="true" ItemPlaceholderID="webpageContainer" AllowPaging="true" DataKeyNames="id" Skin="WebBlue" OnItemDataBound="lstVwWebpageList_ItemDataBound" OnPageIndexChanged="lstVwWebpageList_PageChange" Width="607px" OnItemCommand="lstVwWebpageList_ItemCommand">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:PlaceHolder ID="webpageContainer" runat="server" />
</td>
</tr>
<tr>
<td>
<telerik:RadDataPager ID="Pager" runat="server" PagedControlID="lstVwWebpageList" PageSize="50" Skin="WebBlue">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" />
</Fields>
</telerik:RadDataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<fieldset style="float: left; width: 300px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="width: 25%;">
<b>Name:</b>
</td>
<td style="width: 75%;">
<asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 25%;">
<b>Page:</b>
</td>
<td style="width: 75%;">
<asp:LinkButton ID="pagenameLink" runat="server" OnClick="test" OnCommand="testing" CommandName="LinkClicked" Text='<%# Eval("pagename") %>' PostBackUrl='<%# "EditWebpage.aspx?name=" + Eval("name") + "&page=" + Eval("pagename") %>'></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</fieldset>
</ItemTemplate>
protected void lstVwWebpageList_ItemCommand(object sender, RadListViewCommandEventArgs e)
{
if (e.CommandName == "LinkClicked")
{
RadListViewDataItem item = (RadListViewDataItem)e.ListViewItem;
Session["linkID"] = item.DataItem;
}
}
答案 0 :(得分:0)
试试这个
<asp:LinkButton runat="server"
ID="pagenameLink"
Text='<%# Eval("pagename") %>'
CommandName="LinkClicked"
CommandArgument='<%#Eval("name") + ", " + Eval("pagename") %>' />