Reputation: 339
net
I have the following BulletedList in my aspx file
<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>
What I want to do is in my CS file, I would like to assing the below
Sting filepath = // here i want to get the ListItem Value
Sting filename = // here i want to get the file name present in Listitem text.
How do i get the above two values in the below button click event.
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
}
Upvotes: 0
Views: 168
Reputation: 63065
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
ListItem li = DocumentList.Items[e.Index];
Sting filepath = li.Value;
Sting filename = li.Text;
}
But you don't need To specify text field to hold value of file name, you can get it from path.
<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>
then
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);
}
Upvotes: 1
Reputation: 1659
protected void DocumentList_Click(object sender, BulletedListEventArgs e)
{
var item = DocumentList.Items[e.Index];
String filepath = item.Value;
String filename = item.Text;
}
Upvotes: 0