【问题标题】:Display Listview item's where userid == item owner显示 Listview 项目的用户 ID == 项目所有者
【发布时间】:2017-11-07 08:19:28
【问题描述】:

我想显示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> &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>

【问题讨论】:

  • 不要粘贴代码图像,而是直接将代码发布到您的问题中。让可能有相同问题的其他读者更容易找到您的解决方案。
  • 是的,我只是想比较 2 个值以在列表视图上显示在数据表上具有相同值的内容。

标签: c# asp.net


【解决方案1】:

在“SQL DATASOURCE”上选择configure,选择表并点击“WHERE”,选择“Column” 注意:你要比较什么表,“Operator”是'=',“Source”是“Control”选择'TextBox1 ' 然后点击 "ADD" 然后点击 'Ok','Ok',Finish 。

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多