我想显示ListView
项目。这些项目将显示为=添加它的用户。我已经获得了userid
“curentuser”和ownerid
,但Listview
显示了Sql数据表中的所有项目。我的问题是要显示的ListView
项必须过滤给仅添加它的用户。这两个代码不是更新,而只是显示,如何在'listview'上显示与'userid'具有相同值的数据?
这是我的代码CSS:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uname"] != null ) //get userid(login user) for table display control
{
Class1.con.Open();
string display = "select * from tbl_Prof where UserName='" + Session["uname"] + "'";
SqlCommand com = new SqlCommand(display, Class1.con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
da.Fill(ds);
txtcode3.Text = ds.Tables[0].Rows[0]["profid"].ToString();
Class1.con.Close();
}
else { }
Class1.con.Open(); //get userid( user login table creator) for table display control
string display1 = "select * from tbl_Schead where userid='" + txtcode3.Text + "'";
SqlCommand com1 = new SqlCommand(display1, Class1.con);
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
txtcode2.Text = ds1.Tables[0].Rows[0]["userid"].ToString();
Class1.con.Close();
}
这是列表视图asp.net:
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="ListView1_ItemCommand" >
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color:#E5E5FE">
<th align="left"><asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton> </th>
<th ><asp:LinkButton ID="lnkName" runat="server">DAY</asp:LinkButton> </th>
<th><asp:LinkButton ID="lnkType" runat="server">TIME</asp:LinkButton> </th>
<th><asp:LinkButton ID="LinkButton1" runat="server">COURSE</asp:LinkButton> </th>
<th><asp:LinkButton ID="LinkButton2" runat="server">STUDENT COUNT</asp:LinkButton> </th>
<th></th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:Label runat="server" ID="lblId"><%#Eval("sid") %></asp:Label>
</td>
<td><asp:Label runat="server" ID="lblName"><%#Eval("sday") %></asp:Label>
</td>
<td><asp:Label runat="server" ID="lblType"><%#Eval("stime") %>
</asp:Label></td>
<td><asp:Label runat="server" ID="Label1"><%#Eval("scourse") %>
</asp:Label></td>
<td><asp:Label runat="server" ID="Label2"><%#Eval("sstudcount") %>
</asp:Label></td>
<td><asp:Label runat="server" ID="Label3"><%#Eval("userid") %>
</asp:Label></td>
<th>
<asp:Button ID="Button1" runat="server" Text="VIEW" CommandName="VIEW" CommandArgument= '<%#Eval("userid")%>'/>
<td></td>
</tr>
</ItemTemplate>
</asp:ListView>