创建列表视图 [英] To create a list view
本文介绍了创建列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Report中使用DataSource创建一个listView,其中列表应包含可以建立链接的项目。
解决方案
这里是一个示例Listview
以及如何将数据库与Listview
中的链接绑定到使用querystring导航到详细信息页面
< asp:listview runat = 服务器 id = listViewEmp itemplaceholderid = itemPlaceholder xmlns:asp = #unknown >
< layouttemplate >
< table >
< tr runat = < span class =code-keyword> server id = itemPlaceholder > < / tr >
< / table >
< / layouttemplate >
< itemtemplate >
< tr >
< td > ;
< asp:超链接 id = lnkView runat = server text = <% #Eval( 名称)%> navigateurl = <%# ViewDetail.aspx?EmpID = + Eval( EmployeeID)%> < span class =code-attribute> / >
< / td >
< / tr >
< span class =code-keyword>< / itemtemplate >
< / asp:listview >和c#代码绑定
private void Page_Load( object sender,System.EventArgs e)
{
string connString = 您的连接字符串;
string sql = @ 选择*来自雇员跨度>;
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(sql,conn);
da.Fill(dataSet1, employee);
DataTable dt = dataSet1.Tables [ employee];
listViewEmp.DataSource = dt;
listViewEmp.DataBind();
}
在此示例中,有一个链接可查看将重定向到Detail.aspx的Employee的详细信息
希望这会让你更好地理解你的任务。
你可以使用你的listview项目作为超链接
尝试类似
< asp:ListView runat = server ID = lvItems
< span class =code-attribute>
DataSourceID = SqlDataSourceBind DataKeyNames = ID >
< ItemTemplate >
< asp:HyperLink ID = linkID runat = server
< span class =code-attribute> 目标 = _ blank 文本 =' <% #Eval( 名称)%> '
< span class =code-attribute> NavigateUrl =' <%# ShowUrl.aspx?ID = +
Eval ( ID)%> ' / >
< / ItemTemplate >
< / asp:ListView >
希望这有助于
< asp:listview runat = server id = listViewEmp itemplaceholderid = itemPlaceholder xmlns:asp = #unknown >
< layouttemplate>
< table>
< tr runat = server id = itemPlaceholder > < ; / tr >
< / 表格 >
< / layouttemplate >
< itemtemplate>
< tr>
< td>
< asp:hyperlink id = lnkView runat = server text = <%#Eval(名称 )%> navigateurl = <%# ViewDetail.aspx?ItemID = + Eval( ItemID ) %> />
< / td >
< / tr >
< / itemtemplate >
< / asp:listview > 跨度>
I want to create a "listView" using DataSource in Report, in which the list should contain item which can make a link.
解决方案
Hi,
here is a sampleListview
and how to bind it from databse with links in theListview
to navigate to detail page withquerystring
<asp:listview runat="server" id="listViewEmp" itemplaceholderid="itemPlaceholder" xmlns:asp="#unknown"> <layouttemplate> <table> <tr runat="server" id="itemPlaceholder"></tr> </table> </layouttemplate> <itemtemplate> <tr> <td> <asp:hyperlink id="lnkView" runat="server" text="<%#Eval("Name") %>" navigateurl="<%#"ViewDetail.aspx?EmpID="+ Eval("EmployeeID") %>" /> </td> </tr> </itemtemplate> </asp:listview>and c# code to bind
private void Page_Load(object sender, System.EventArgs e) { string connString = "Your connectionstring"; string sql = @"Select * From Employees"; SqlConnection conn = new SqlConnection(connString); SqlDataAdapter da = new SqlDataAdapter(sql, conn); da.Fill(dataSet1, "employee"); DataTable dt = dataSet1.Tables["employee"]; listViewEmp.DataSource = dt; listViewEmp.DataBind(); }
In this example there is a Link to view the details of Employee that will redirect toDetail.aspx
Hope this will give you better idea to acieve your task.
You can use your listview item as a hyperlink
Try something like
<asp:ListView runat="server" ID="lvItems" DataSourceID="SqlDataSourceBind" DataKeyNames="ID"> <ItemTemplate> <asp:HyperLink ID="linkID" runat="server" Target="_blank" Text='<% #Eval("Name")%>' NavigateUrl='<%#"ShowUrl.aspx?ID=" + Eval("ID") %>' /> </ItemTemplate> </asp:ListView>
Hope this helps
<asp:listview runat="server" id="listViewEmp" itemplaceholderid="itemPlaceholder" xmlns:asp="#unknown"> <layouttemplate> <table> <tr runat="server" id="itemPlaceholder"></tr> </table> </layouttemplate> <itemtemplate> <tr> <td> <asp:hyperlink id="lnkView" runat="server" text="<%#Eval("Name") %>" navigateurl="<%#"ViewDetail.aspx?ItemID="+ Eval("ItemID") %>" /> </td> </tr> </itemtemplate> </asp:listview>
这篇关于创建列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文