Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 显示列表视图项';其中userid==项目所有者_C#_Asp.net - Fatal编程技术网

C# 显示列表视图项';其中userid==项目所有者

C# 显示列表视图项';其中userid==项目所有者,c#,asp.net,C#,Asp.net,我想显示ListView项。这些项目将显示给添加它的用户。我已经获得了userid“curentuser”和ownerid,但是列表视图显示了Sql数据表上的所有项。我的问题是,要显示的ListView项必须筛选给只添加它的用户。这两段代码并没有更新,只是在显示,您知道如何在“listview”上显示与“userid”值相同的数据吗 以下是我的CSS代码: protected void Page_Load(object sender, EventArgs e) { if (Sessio

我想显示
ListView
项。这些项目将显示给添加它的用户。我已经获得了
userid
“curentuser”和
ownerid
,但是
列表视图显示了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数据源”上选择配置,选择表格并单击“位置”,选择“列”注意:要比较的表格,“运算符”是“=”,“源”是“控件”,选择“TextBox1”,然后点击“添加”,然后点击“确定”,“确定”,完成。

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