net
我的aspx文件中有以下BulletedList
<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文件中,我想解决以下问题
Sting filepath = // here i want to get the ListItem Value
Sting filename = // here i want to get the file name present in Listitem text.如何在下面的按钮单击事件中获取上述两个值。
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
}发布于 2013-03-18 23:02:55
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
ListItem li = DocumentList.Items[e.Index];
Sting filepath = li.Value;
Sting filename = li.Text;
}但是你不需要指定文本字段来保存文件名的值,你可以从路径中获取它。
<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>然后
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);
}发布于 2013-03-18 23:02:27
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
var item = DocumentList.Items[e.Index];
String filepath = item.Value;
String filename = item.Text;
}https://stackoverflow.com/questions/15479893
复制相似问题