首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >调用CS文件中BulletedList中存在的ListItem

调用CS文件中BulletedList中存在的ListItem
EN

Stack Overflow用户
提问于 2013-03-18 22:57:41
回答 2查看 159关注 0票数 0

net

我的aspx文件中有以下BulletedList

代码语言:javascript
复制
<asp:BulletedList ID="DocumentList" runat="server" 
DisplayMode="LinkButton" onclick="DocumentList_Click">
    <asp:ListItem Value="Documents/testpage.pdf" Text="testpage.pdf" >test page</asp:ListItem>
    <asp:ListItem Value="Documents/testpage2.pdf" Text="testpage2.pdf">test page 2</asp:ListItem>
</asp:BulletedList>

我想要做的是在我的CS文件中,我想解决以下问题

代码语言:javascript
复制
Sting filepath = // here i want to get the ListItem Value
Sting filename = // here i want to get the file name present in Listitem text.

如何在下面的按钮单击事件中获取上述两个值。

代码语言:javascript
复制
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-18 23:02:55

代码语言:javascript
复制
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
     ListItem li = DocumentList.Items[e.Index];
     Sting filepath = li.Value;
     Sting filename = li.Text;

}

但是你不需要指定文本字段来保存文件名的值,你可以从路径中获取它。

代码语言:javascript
复制
<asp:BulletedList ID="DocumentList" runat="server" 
DisplayMode="LinkButton" onclick="DocumentList_Click">
    <asp:ListItem Value="Documents/testpage.pdf" >test page</asp:ListItem>
    <asp:ListItem Value="Documents/testpage2.pdf" >test page 2</asp:ListItem>
</asp:BulletedList>

然后

代码语言:javascript
复制
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
     ListItem li = DocumentList.Items[e.Index];
     Sting filepath = li.Value;
     Sting filename = System.IO.Path.GetFileName(li.Value);

}
票数 1
EN

Stack Overflow用户

发布于 2013-03-18 23:02:27

代码语言:javascript
复制
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
    var item = DocumentList.Items[e.Index];
    String filepath = item.Value;
    String filename = item.Text;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15479893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档