如何将gridview项目模板绑定到数据库存储过程? [英] how to bind gridview item template to DB stored procedure?

查看:55
本文介绍了如何将gridview项目模板绑定到数据库存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我有一个gridview,并且在gridview里面有一个模板字段,所以我想将此模板字段的标签(项目模板)绑定到sqlserver中的存储过程,并将标签文本更改为从存储过程中选择的文本.
这是存储过程:

Hi.

I have a gridview and inside the gridview there is a templated field , so i want to bind the lable of this templated field(item template) to the stored procedure in the sqlserver , and to change the lable text to what is selected from stored procedure .
here is the stored procedure :

ALTER PROCEDURE [dbo].[Get_LastIdHowzeEducationFinishDate_SP]
AS
BEGIN 
select he.FinishLevelDate as 'تاریخ اتمام سطح'
       from PersonHowEducation prh inner join HowzeEducation he on 
              prh.HowzeEducationId=he.HowzeEducationId
              where prh.IdCode=
              (Select IdCode from Persons where IdCode=IDENT_CURRENT('persons'))
END



这是用于调用存储过程并在lable(item template)中显示它的代码:



and this is the code for calling stored procedure and to show it inside lable(item template):

DataTable dt1 = DataProvider.ExecuteDataTable("[dbo].[Get_LastIdHowzeEducationFinishDate_SP]", CommandType.StoredProcedure);
GridView1.FindControl("Label1").DataBind();



但出现此异常:
对象引用未设置为对象的实例
我该怎么做?



but this exception appears:
Object reference not set to an instance of an object
how can i do that?

推荐答案

将您的ASPX页面的代码发布到已定义GridView的位置.

对于绑定,您将需要使用以下语句-
Post the code of your ASPX page where you have defined the GridView.

For Binding, you will need to use the below statement -
GridView1.DataSource = dt1;
GridView1.DataBind();


这篇关于如何将gridview项目模板绑定到数据库存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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