asp.net中的gridview显示 [英] gridview display in asp.net

查看:57
本文介绍了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没有显示在窗体中...



问题在哪里

解决方案

很少你可以照顾的东西。



首先在SQL查询编辑器中运行带有预期用户ID的存储过程,看看你是否得到了所需的输出。 br />


将您的连接字符串放在Web Config文件中,然后在您的函数中放置一个调试器,该函数返回数据表,另一个在gridview绑定数据源。



并将你的gridview绑定写入

  if (!ispostback)
{
GridView1.DataSource = dwww.getdocall1(Convert.ToInt32(Session [ 用户ID]));
GridView1.DataBind();
}





在您的页面上加载



和(我想只是尝试)它应该是---

 GridView1.DataSource = dtResult 





希望这有助于


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

解决方案

There are few things that you can look after.

At first run the stored Procedure with the expected userID in SQL query editor and see if you are getting the desired output or not.

Put Your Connection String in Web Config file and then put a debugger at your function which is returning the datatable and another at the gridview binding the datasource.

and write your gridview binding into

if(!ispostback)
{
GridView1.DataSource = dwww.getdocall1(Convert.ToInt32(Session["UserID"]));
GridView1.DataBind();
}



on your page load

and (I think just try) It should be---

GridView1.DataSource = dtResult



Hope this helps


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆