net中的gridview显示

net中的gridview显示

本文介绍了asp.net中的gridview显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试显示具有特定部门ID的文档,例如hr admin登录然后他/她只能查看hr文档

i使用thissp和代码完成



sp



 创建  procedure  [dbo]。[dddddd] 
@ userid int
as
SELECT di.DocID,
di .DocName,
di.Uploadfile,
dt.DocType,
d.DepType,
at.ApproveType
FROM DocumentInfo di
JOIN
DocType dt ON dt.DocTypeID = di .DocTypeID
JOIN
部门d ON d.DepID = di.DepID


join
用户 ON d.DepID = dbo.Userss.DepID AND di.DocID = dbo.Userss.DocID

LEFT OUTER JOIN
批准a ON a.DocID = di.DocID
JOIN
ON at.ApproveID = ISNULL(a.Approveid, 3

其中 Userss.USERID=@userid







i创建一个函数

  public  DataTable getdocall1( int  userid)
{
// 返回db.ExecuteDataSet(dddddd)。Tables [0];
string connectionString = @ Database = DMSFYPP; Server = LENOVO-PC\SQLEXPRESS; Integrated Security = True;
使用(SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand( dddddd,连接);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.AddWithValue( @ userid,userid);

connection.Open();

DataTable dtResult = new DataTable();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);
sqlDataAdapter.Fill(dtResult);

return dtResult;
}
}





然后我在页面加载中调用它

 受保护  void  Page_Load( object  sender,EventArgs e)
{
GridView1.DataSource = dwww.getdocall1(Convert.ToInt32(Session [ UserID]));
GridView1.DataBind();
}







但是当我调试代码时..代码有效很好,但gridview没有显示在窗体中...



问题在哪里

解决方案

i try to show documents with specidic department id like when hr admin login then he/she able to view only hr documents
i done with thissp and code

sp

create procedure [dbo].[dddddd]
@userid int
as
SELECT  di.DocID,
        di.DocName,
        di.Uploadfile,
        dt.DocType,
        d.DepType,
        at.ApproveType
FROM    DocumentInfo di
    JOIN
        DocType dt ON dt.DocTypeID = di.DocTypeID
    JOIN
        Department d ON d.DepID = di.DepID


           join
        Userss ON d.DepID = dbo.Userss.DepID AND di.DocID = dbo.Userss.DocID

    LEFT OUTER JOIN
        Approval a ON a.DocID = di.DocID
    JOIN
        ApproveType at ON at.ApproveID = ISNULL(a.Approveid, 3)

        where  Userss.USERID=@userid    




i create a function

public DataTable getdocall1(int userid)
       {
           //return db.ExecuteDataSet("dddddd").Tables[0];
           string connectionString = @"Database=DMSFYPP;Server=LENOVO-PC\SQLEXPRESS;Integrated Security=True";
           using (SqlConnection connection = new SqlConnection(connectionString))
           {
               SqlCommand command = new SqlCommand("dddddd", connection);
               command.CommandType = System.Data.CommandType.StoredProcedure;
               command.Parameters.AddWithValue("@userid", userid);

               connection.Open();

               DataTable dtResult = new DataTable();
               SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);
               sqlDataAdapter.Fill(dtResult);

               return dtResult;
           }
       }



then i call this in page load

protected void Page_Load(object sender, EventArgs e)
       {
           GridView1.DataSource = dwww.getdocall1(Convert.ToInt32(Session["UserID"]));
           GridView1.DataBind();
       }




but when i debug the code ..code works fine but gridview not display in form...

where is the problem

解决方案


这篇关于asp.net中的gridview显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 22:12