使用网格视图显示存储过程 [英] Displaying Stored Procedures using Grid View

查看:53
本文介绍了使用网格视图显示存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




使用.net 2

sql server 2005


这是我的情况:


我在页面A上的选项中传递了一个变量,需要

来显示结果页面上的结果基于该变量

在网址中。我希望该变量在formView或Grid View中触发存储的和/ b
显示信息。什么是最好的方式来实现这个目标?


Page A


这是从网格视图传递var:

< asp:HyperLinkField DataTextField ="未决问题"

DataNavigateUrlFields ="票号"

DataNavigateUrlFormatString =" results2.aspx ?{0}" Target =" _blank"

HeaderText =" Open Issues" />


结果页面


< asp:FormView ID =" FormView1" RUNAT = QUOT;服务器" DataKeyNames =" Ticket

Number"

DataSourceID =" SqlDataSource1"

OnPageIndexChanging =" FormView1_PageIndexChanging">

< EditItemTemplate>

票号:

< asp:Label ID =" Ticket_NumberLabel1" runat =" server"

Text =''<%#Eval(" [Ticket Number]")%>''>

< / asp:标签>< br />

技术员已分配:

< asp:TextBox ID =" Technician_AssignedTextBox"

runat = QUOT;服务器" Text =''<%#Bind(" [Technician Assigned]")%>''>

< / asp:TextBox>< br />

问题描述:

< asp:TextBox ID =" Issue_DescriptionTextBox"

runat =" server" Text =''<%#Bind(" [Issue Description]")%>''>

< / asp:TextBox>< br />

开放日期:

< asp:TextBox ID =" Open_DateTextBox" runat =" server"

Text =''<%#Bind(" [Open Date]")%>''>

< / asp:TextBox>< br />

工作说明:

< asp:TextBox ID =" Work_NotesTextBox" runat =" server"

Text =''<%#Bind(" [Work Notes]")%>''>

< / asp:TextBox>< br />

< asp:LinkBut​​ton ID =" UpdateButton" runat =" server"

CausesValidation =" True" CommandName ="更新"

文字="更新">

< / asp:LinkBut​​ton>

< asp:LinkBut​​ton ID =" UpdateCancelButton"

runat =" server"的CausesValidation = QUOT假QUOT; CommandName =" Cancel"

Text =" Cancel">

< / asp:LinkBut​​ton>

< / EditItemTemplate>

< InsertItemTemplate>

票号:

< asp:TextBox ID =" Ticket_NumberTextBox"

RUNAT = QUOT;服务器" Text =''<%#Bind(" [Ticket Number]")%>''>

< / asp:TextBox>< br />

技术员已分配:

< asp:TextBox ID =" Technician_AssignedTextBox"

runat =" server" Text =''<%#Bind(" [Technician Assigned]")%>''>

< / asp:TextBox>< br />

问题描述:

< asp:TextBox ID =" Issue_DescriptionTextBox"

runat =" server" Text =''<%#Bind(" [Issue Description]")%>''>

< / asp:TextBox>< br />

开放日期:

< asp:TextBox ID =" Open_DateTextBox" runat =" server"

Text =''<%#Bind(" [Open Date]")%>''>

< / asp:TextBox>< br />

工作说明:

< asp:TextBox ID =" Work_NotesTextBox" runat =" server"

Text =''<%#Bind(" [Work Notes]")%>''>

< / asp:TextBox>< br />

< asp:LinkBut​​ton ID =" InsertButton" runat =" server"

CausesValidation =" True" CommandName =" Insert"

Text =" Insert">

< / asp:LinkBut​​ton>

< asp:LinkBut​​ton ID =" InsertCancelButton"

runat =" server"的CausesValidation = QUOT假QUOT; CommandName =" Cancel"

Text =" Cancel">

< / asp:LinkBut​​ton>

< / InsertItemTemplate>

< ItemTemplate>

票号:

< asp:Label ID =" Ticket_NumberLabel" runat =" server"

Text =''<%#Eval(" [Ticket Number]")%>''>

< / asp:标签>< br />

技术员已分配:

< asp:Label ID =" Technician_AssignedLabel"

runat = QUOT;服务器" Text =''<%#Bind(" [Technician Assigned]")%>''>

< / asp:Label>< br />

问题描述:

< asp:Label ID =" Issue_DescriptionLabel"

runat =" server" Text =''<%#Bind(" [Issue Description]")%>''>

< / asp:Label>< br />

开放日期:

< asp:Label ID =" Open_DateLabel" runat =" server"

Text =''<%#Bind(" [Open Date]")%>''>

< / asp:标签>< br />

工作说明:

< asp:Label ID =" Work_NotesLabel" runat =" server"

Text =''<%#Bind(" [Work Notes]")%>''>

< / asp:标签>< br />

< / ItemTemplate>

< / asp:FormView>

解决方案

5月6日下午6:29,brwalias< brwal ... @ gmail.comwrote:

$ b $


使用.net 2

sql server 2005


这是我的情况:


我在网页上的一个选项中传递了一个变量,需要

来显示结果页面上的结果基于该变量

在网址中。我希望该变量在formView或Grid View中触发存储的和/ b
显示信息。什么是最好的方式来实现这个目标?


Page A


这是从网格视图传递var:

< asp:HyperLinkField DataTextField ="未决问题"

DataNavigateUrlFields ="票号"

DataNavigateUrlFormatString =" results2.aspx ?{0}" Target =" _blank"

HeaderText =" Open Issues" />


结果页面


< asp:FormView ID =" FormView1" RUNAT = QUOT;服务器" DataKeyNames =" Ticket

Number"

DataSourceID =" SqlDataSource1"

OnPageIndexChanging =" FormView1_PageIndexChanging">

< EditItemTemplate>

票号:

< asp:Label ID =" Ticket_NumberLabel1" runat =" server"

Text =''<%#Eval(" [Ticket Number]")%>''>

< / asp:标签>< br />

技术员已分配:

< asp:TextBox ID =" Technician_AssignedTextBox"

runat = QUOT;服务器" Text =''<%#Bind(" [Technician Assigned]")%>''>

< / asp:TextBox>< br />

问题描述:

< asp:TextBox ID =" Issue_DescriptionTextBox"

runat =" server" Text =''<%#Bind(" [Issue Description]")%>''>

< / asp:TextBox>< br />

开放日期:

< asp:TextBox ID =" Open_DateTextBox" runat =" server"

Text =''<%#Bind(" [Open Date]")%>''>

< / asp:TextBox>< br />

工作说明:

< asp:TextBox ID =" Work_NotesTextBox" runat =" server"

Text =''<%#Bind(" [Work Notes]")%>''>

< / asp:TextBox>< br />

< asp:LinkBut​​ton ID =" UpdateButton" runat =" server"

CausesValidation =" True" CommandName ="更新"

文字="更新">

< / asp:LinkBut​​ton>

< asp:LinkBut​​ton ID =" UpdateCancelButton"

runat =" server"的CausesValidation = QUOT假QUOT; CommandName =" Cancel"

Text =" Cancel">

< / asp:LinkBut​​ton>

< / EditItemTemplate>

< InsertItemTemplate>

票号:

< asp:TextBox ID =" Ticket_NumberTextBox"

RUNAT = QUOT;服务器" Text =''<%#Bind(" [Ticket Number]")%>''>

< / asp:TextBox>< br />

技术员已分配:

< asp:TextBox ID =" Technician_AssignedTextBox"

runat =" server" Text =''<%#Bind(" [Technician Assigned]")%>''>

< / asp:TextBox>< br />

问题描述:

< asp:TextBox ID =" Issue_DescriptionTextBox"

runat =" server" Text =''<%#Bind(" [Issue Description]")%>''>

< / asp:TextBox>< br />

开放日期:

< asp:TextBox ID =" Open_DateTextBox" runat =" server"

Text =''<%#Bind(" [Open Date]")%>''>

< / asp:TextBox>< br />

工作说明:

< asp:TextBox ID =" Work_NotesTextBox" runat =" server"

Text =''<%#Bind(" [Work Notes]")%>''>

< / asp:TextBox>< br />

< asp:LinkBut​​ton ID =" InsertButton" runat =" server"

CausesValidation =" True" CommandName =" Insert"

Text =" Insert">

< / asp:LinkBut​​ton>

< asp:LinkBut​​ton ID =" InsertCancelButton"

runat =" server"的CausesValidation = QUOT假QUOT; CommandName =" Cancel"

Text =" Cancel">

< / asp:LinkBut​​ton>

< / InsertItemTemplate>

< ItemTemplate>

票号:

< asp:Label ID =" Ticket_NumberLabel" runat =" server"

Text =''<%#Eval(" [Ticket Number]")%>''>

< / asp:标签>< br />

技术员已分配:

< asp:Label ID =" Technician_AssignedLabel"

runat = QUOT;服务器" Text =''<%#Bind(" [Technician Assigned]")%>''>

< / asp:Label>< br />

问题描述:

< asp:Label ID =" Issue_DescriptionLabel"

runat =" server" Text =''<%#Bind(" [Issue Description]")%>''>

< / asp:Label>< br />

开放日期:

< asp:Label ID =" Open_DateLabel" runat =" server"

Text =''<%#Bind(" [Open Date]")%>''>

< / asp:标签>< br />

工作说明:

< asp:Label ID =" Work_NotesLabel" runat =" server"

Text =''<%#Bind(" [Work Notes]")%>''>

< / asp:标签>< br />

< / ItemTemplate>

< / asp:FormView>



SqlDataSource控件有一个SelectParameter部分,您可以在其中为
指定查询参数。有一个QueryStringParameter

部分用于将查询字符串的值绑定到参数化查询中使用的参数




因此,您的代码如下所示


< asp:SqlDataSource ID =" SqlDataSource1"

SelectCommand =" SELECT .... WHERE state = @ state"

....>

< SelectParameters>

< asp:QueryStringParameter Name =" state" ; QueryStringField = QUOT;状态" />

< / SelectParameters>

< / asp:SqlDataSource>


其中:


名称是@parameter的名称

QueryStringField是QueryString的关键部分


注意,QueryStringParameter的使用不从客户端执行任何

验证输入和实现这个代码隐藏模型的真正最佳方式。


QueryStringParameter不以任何方式验证

查询字符串传递的值;它使用原始值。在


5月6日晚上8:53,Alexey Smirnov< alexey.smir ... @ gmail.comwrote:


>

QueryStringParameter不以任何方式验证

查询字符串传递的值;它使用原始值。 In-隐藏引用文本 -



发送按钮太快:QueryStringParameter不验证查询字符串传递给任何值的
办法;它使用原始的

值。在大多数情况下,您可以在数据源控件使用

处理事件(如选择,更新,插入,或者

删除您正在使用的数据源控件公开的事件。如果

参数的值没有通过验证测试,那么你可以通过设置

的取消属性取消数据操作将CancelEventArgs类关联为true。

http://msdn2.microsoft.com/en-us/lib...er(VS.80).aspx


页面A:


这是一个超级链接,表示从sql生成的ticketid

用户将点击查看行。一旦点击,一个新窗口需要

打开存储在存储的

程序中的该行的其他详细信息。


< ; asp:HyperLinkField DataTextField =" Open Issues"
DataNavigateUrlFields =" Ticket Number"

DataNavigateUrlFormatString =" results2.aspx?ticketi d = {0}"

Target =" _blank" HeaderText =未解决的问题 />


--------------------------


var似乎已经过了,因为我在结果页面上打印只是为了确认

。我还添加了详细信息视图,如下所示:


< asp:DataList ID =" DataList1" RUNAT = QUOT;服务器" DataKeyField =" Ticket

Number" DataSourceID =" SqlDataSource1">


< ItemTemplate>

票号:

< asp:Label ID = " Ticket_NumberLabel" runat =" server"

Text =''<%#Eval(" [Ticket Number]")%>''>

< / asp:标签>< br />

技术员已分配:

< asp:Label ID =" Technician_AssignedLabel"

runat = QUOT;服务器" Text =''<%#Eval(" [Technician Assigned]")%>''>

< / asp:Label>< br />

问题描述:

< asp:Label ID =" Issue_DescriptionLabel"

runat =" server" Text =''<%#Eval(" [Issue Description]")%>''>

< / asp:Label>< br />

开放日期:

< asp:Label ID =" Open_DateLabel" runat =" server"

Text =''<%#Eval(" [Open Date]")%>''>

< / asp:标签>< br />

工作说明:

< asp:Label ID =" Work_NotesLabel" runat =" server"

Text =''<%#Eval(" [Work Notes]")%>''>

< / asp:标签>< br />

< br />

< / ItemTemplate>

< / asp :DataList>< asp:SqlDataSource ID =" SqlDataSource1"

runat =" server"的ConnectionString = QUOT;<%

Hi,

using .net 2
sql server 2005

Here is my situation:

I''m passing a variable in the url from a selection on Page A and need
to display the results on the Results page be based on that variable
in the url. I would like that variable to trigger a stored and
display information in formView or Grid View. Whats the best way to
accomplish this?

Page A

This is passing var from grid view:
<asp:HyperLinkField DataTextField="Open Issues"
DataNavigateUrlFields="Ticket Number"
DataNavigateUrlFormatString="results2.aspx?{0}" Target="_blank"
HeaderText="Open Issues" />

Results Page

<asp:FormView ID="FormView1" runat="server" DataKeyNames="Ticket
Number"
DataSourceID="SqlDataSource1"
OnPageIndexChanging="FormView1_PageIndexChanging">
<EditItemTemplate>
Ticket Number:
<asp:Label ID="Ticket_NumberLabel1" runat="server"
Text=''<%# Eval("[Ticket Number]") %>''>
</asp:Label><br />
Technician Assigned:
<asp:TextBox ID="Technician_AssignedTextBox"
runat="server" Text=''<%# Bind("[Technician Assigned]") %>''>
</asp:TextBox><br />
Issue Description:
<asp:TextBox ID="Issue_DescriptionTextBox"
runat="server" Text=''<%# Bind("[Issue Description]") %>''>
</asp:TextBox><br />
Open Date:
<asp:TextBox ID="Open_DateTextBox" runat="server"
Text=''<%# Bind("[Open Date]") %>''>
</asp:TextBox><br />
Work Notes:
<asp:TextBox ID="Work_NotesTextBox" runat="server"
Text=''<%# Bind("[Work Notes]") %>''>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Ticket Number:
<asp:TextBox ID="Ticket_NumberTextBox"
runat="server" Text=''<%# Bind("[Ticket Number]") %>''>
</asp:TextBox><br />
Technician Assigned:
<asp:TextBox ID="Technician_AssignedTextBox"
runat="server" Text=''<%# Bind("[Technician Assigned]") %>''>
</asp:TextBox><br />
Issue Description:
<asp:TextBox ID="Issue_DescriptionTextBox"
runat="server" Text=''<%# Bind("[Issue Description]") %>''>
</asp:TextBox><br />
Open Date:
<asp:TextBox ID="Open_DateTextBox" runat="server"
Text=''<%# Bind("[Open Date]") %>''>
</asp:TextBox><br />
Work Notes:
<asp:TextBox ID="Work_NotesTextBox" runat="server"
Text=''<%# Bind("[Work Notes]") %>''>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
Ticket Number:
<asp:Label ID="Ticket_NumberLabel" runat="server"
Text=''<%# Eval("[Ticket Number]") %>''>
</asp:Label><br />
Technician Assigned:
<asp:Label ID="Technician_AssignedLabel"
runat="server" Text=''<%# Bind("[Technician Assigned]") %>''>
</asp:Label><br />
Issue Description:
<asp:Label ID="Issue_DescriptionLabel"
runat="server" Text=''<%# Bind("[Issue Description]") %>''>
</asp:Label><br />
Open Date:
<asp:Label ID="Open_DateLabel" runat="server"
Text=''<%# Bind("[Open Date]") %>''>
</asp:Label><br />
Work Notes:
<asp:Label ID="Work_NotesLabel" runat="server"
Text=''<%# Bind("[Work Notes]") %>''>
</asp:Label><br />
</ItemTemplate>
</asp:FormView>

解决方案

On May 6, 6:29 pm, brwalias <brwal...@gmail.comwrote:

Hi,

using .net 2
sql server 2005

Here is my situation:

I''m passing a variable in the url from a selection on Page A and need
to display the results on the Results page be based on that variable
in the url. I would like that variable to trigger a stored and
display information in formView or Grid View. Whats the best way to
accomplish this?

Page A

This is passing var from grid view:
<asp:HyperLinkField DataTextField="Open Issues"
DataNavigateUrlFields="Ticket Number"
DataNavigateUrlFormatString="results2.aspx?{0}" Target="_blank"
HeaderText="Open Issues" />

Results Page

<asp:FormView ID="FormView1" runat="server" DataKeyNames="Ticket
Number"
DataSourceID="SqlDataSource1"
OnPageIndexChanging="FormView1_PageIndexChanging">
<EditItemTemplate>
Ticket Number:
<asp:Label ID="Ticket_NumberLabel1" runat="server"
Text=''<%# Eval("[Ticket Number]") %>''>
</asp:Label><br />
Technician Assigned:
<asp:TextBox ID="Technician_AssignedTextBox"
runat="server" Text=''<%# Bind("[Technician Assigned]") %>''>
</asp:TextBox><br />
Issue Description:
<asp:TextBox ID="Issue_DescriptionTextBox"
runat="server" Text=''<%# Bind("[Issue Description]") %>''>
</asp:TextBox><br />
Open Date:
<asp:TextBox ID="Open_DateTextBox" runat="server"
Text=''<%# Bind("[Open Date]") %>''>
</asp:TextBox><br />
Work Notes:
<asp:TextBox ID="Work_NotesTextBox" runat="server"
Text=''<%# Bind("[Work Notes]") %>''>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Ticket Number:
<asp:TextBox ID="Ticket_NumberTextBox"
runat="server" Text=''<%# Bind("[Ticket Number]") %>''>
</asp:TextBox><br />
Technician Assigned:
<asp:TextBox ID="Technician_AssignedTextBox"
runat="server" Text=''<%# Bind("[Technician Assigned]") %>''>
</asp:TextBox><br />
Issue Description:
<asp:TextBox ID="Issue_DescriptionTextBox"
runat="server" Text=''<%# Bind("[Issue Description]") %>''>
</asp:TextBox><br />
Open Date:
<asp:TextBox ID="Open_DateTextBox" runat="server"
Text=''<%# Bind("[Open Date]") %>''>
</asp:TextBox><br />
Work Notes:
<asp:TextBox ID="Work_NotesTextBox" runat="server"
Text=''<%# Bind("[Work Notes]") %>''>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
Ticket Number:
<asp:Label ID="Ticket_NumberLabel" runat="server"
Text=''<%# Eval("[Ticket Number]") %>''>
</asp:Label><br />
Technician Assigned:
<asp:Label ID="Technician_AssignedLabel"
runat="server" Text=''<%# Bind("[Technician Assigned]") %>''>
</asp:Label><br />
Issue Description:
<asp:Label ID="Issue_DescriptionLabel"
runat="server" Text=''<%# Bind("[Issue Description]") %>''>
</asp:Label><br />
Open Date:
<asp:Label ID="Open_DateLabel" runat="server"
Text=''<%# Bind("[Open Date]") %>''>
</asp:Label><br />
Work Notes:
<asp:Label ID="Work_NotesLabel" runat="server"
Text=''<%# Bind("[Work Notes]") %>''>
</asp:Label><br />
</ItemTemplate>
</asp:FormView>

The SqlDataSource Control has a SelectParameter section where you can
specify parameters for your query. There is the QueryStringParameter
section used to bind the values of the query string to a parameter
used in a parameterized query.

So, your code would be as the follows

<asp:SqlDataSource ID="SqlDataSource1"
SelectCommand="SELECT .... WHERE state=@state"
....>
<SelectParameters>
<asp:QueryStringParameter Name="state" QueryStringField="state" />
</SelectParameters>
</asp:SqlDataSource>

Where:

Name is the name of @parameter
QueryStringField is the key section of the QueryString

Note, usage of the QueryStringParameter does not perform any
validation of input from the client and the real best way to
accomplish this is the code-behind model.

The QueryStringParameter does not validate the value passed by the
query string in any way; it uses the raw value. In


On May 6, 8:53 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:

>
The QueryStringParameter does not validate the value passed by the
query string in any way; it uses the raw value. In- Hide quoted text -

Too quick on send button: The QueryStringParameter does not validate
the value passed by the query string in any way; it uses the raw
value. In most cases you can validate the value of the
QueryStringParameter before it is used by a data source control by
handling an event, such as the Selecting, Updating, Inserting, or
Deleting event exposed by the data source control you are using. If
the value of the parameter does not pass your validation tests, you
can cancel the data operation by setting the Cancel property of the
associated CancelEventArgs class to true.

http://msdn2.microsoft.com/en-us/lib...er(VS.80).aspx


Page A:

This is a hyper link which represents ticketid generated from sql that
the user will click on to view row. once clicked, a new window needs
to open with additional details from that row stored in a stored
procedure.

<asp:HyperLinkField DataTextField="Open Issues"
DataNavigateUrlFields="Ticket Number"
DataNavigateUrlFormatString="results2.aspx?ticketi d={0}"
Target="_blank" HeaderText="Open Issues" />

--------------------------

var seems to pass as i have it printing on the results page just to
confirm. I have also added the details view as follows:

<asp:DataList ID="DataList1" runat="server" DataKeyField="Ticket
Number" DataSourceID="SqlDataSource1">

<ItemTemplate>
Ticket Number:
<asp:Label ID="Ticket_NumberLabel" runat="server"
Text=''<%# Eval("[Ticket Number]") %>''>
</asp:Label><br />
Technician Assigned:
<asp:Label ID="Technician_AssignedLabel"
runat="server" Text=''<%# Eval("[Technician Assigned]") %>''>
</asp:Label><br />
Issue Description:
<asp:Label ID="Issue_DescriptionLabel"
runat="server" Text=''<%# Eval("[Issue Description]") %>''>
</asp:Label><br />
Open Date:
<asp:Label ID="Open_DateLabel" runat="server"
Text=''<%# Eval("[Open Date]") %>''>
</asp:Label><br />
Work Notes:
<asp:Label ID="Work_NotesLabel" runat="server"
Text=''<%# Eval("[Work Notes]") %>''>
</asp:Label><br />
<br />
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1"
runat="server" ConnectionString="<%


这篇关于使用网格视图显示存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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