显示列表视图项目,其中用户 ID == 项目所有者



我想显示ListView项目。这些项目将显示 is = 给添加它的用户。我已经得到了userid"curentuser"和owneridListview显示 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> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</th> 
   <th ><asp:LinkButton ID="lnkName" runat="server">DAY</asp:LinkButton>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</th>
   <th><asp:LinkButton ID="lnkType" runat="server">TIME</asp:LinkButton>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</th>
   <th><asp:LinkButton ID="LinkButton1" runat="server">COURSE</asp:LinkButton>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</th>
   <th><asp:LinkButton ID="LinkButton2" runat="server">STUDENT COUNT</asp:LinkButton>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</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>
在"SQL DATASOURCE"上选择配置,选择表并单击"WHERE",选择"

列"注意:您要比较的表,"运算符"是"=","源"是"控制"选择"TextBox1"并点击"添加",然后点击"确定","确定",完成。

最新更新