2005中GridView 的DataSource中存储过程用到的参数和DataKeyNames的冲突
来源:互联网 发布:centos安装hadoop集群 编辑:程序博客网 时间:2024/05/18 10:21
<asp:GridView ID="gvEvent" runat="server" CellPadding="4" ForeColor="#4761C0" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSourceforgvEvent" DataKeyNames="ID,EventDescription" Width="700px" OnPageIndexChanging="gvEvent_PageIndexChanging" OnDataBound="gvEvent_DataBound">
<FooterStyle BackColor="#4761C0" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" Height="21px" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#4761C0" Font-Bold="True" ForeColor="White" Height="22px" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ID" InsertVisible="False" ReadOnly="True" HeaderText="编号"
SortExpression="ID">
<ItemStyle Width="0px" />
</asp:BoundField>
<asp:BoundField DataField="PoliceName" HeaderText="派出所" />
<asp:BoundField DataField="PlaceName" HeaderText="报警场所" />
<asp:BoundField DataField="EventTime" HeaderText="接警时间" HtmlEncode="False" DataFormatString="{0:yyyy-MM-dd}" />
<asp:BoundField DataField="EventParentCategoryName" HeaderText="事件性质" />
<asp:BoundField DataField="EventChildCategoryName" HeaderText="事件类别" />
<asp:BoundField DataField="EventDescription" HeaderText="事件描述" Visible="False" >
<ItemStyle CssClass="display:none" />
</asp:BoundField>
<asp:CommandField HeaderText="操作" ShowDeleteButton="True" DeleteText="<div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</div>" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceforgvEvent" runat="server" ConnectionString="<%$ ConnectionStrings:PoliceManagerConnectionString %>"
DeleteCommand="UP_Event_Delete" DeleteCommandType="StoredProcedure" SelectCommand="UP_Event_GetList" SelectCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="EventDescription" Type="string" />
</DeleteParameters>
AutoGenerateColumns="False" DataSourceID="SqlDataSourceforgvEvent" DataKeyNames="ID,EventDescription" Width="700px" OnPageIndexChanging="gvEvent_PageIndexChanging" OnDataBound="gvEvent_DataBound">
<FooterStyle BackColor="#4761C0" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" Height="21px" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#4761C0" Font-Bold="True" ForeColor="White" Height="22px" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ID" InsertVisible="False" ReadOnly="True" HeaderText="编号"
SortExpression="ID">
<ItemStyle Width="0px" />
</asp:BoundField>
<asp:BoundField DataField="PoliceName" HeaderText="派出所" />
<asp:BoundField DataField="PlaceName" HeaderText="报警场所" />
<asp:BoundField DataField="EventTime" HeaderText="接警时间" HtmlEncode="False" DataFormatString="{0:yyyy-MM-dd}" />
<asp:BoundField DataField="EventParentCategoryName" HeaderText="事件性质" />
<asp:BoundField DataField="EventChildCategoryName" HeaderText="事件类别" />
<asp:BoundField DataField="EventDescription" HeaderText="事件描述" Visible="False" >
<ItemStyle CssClass="display:none" />
</asp:BoundField>
<asp:CommandField HeaderText="操作" ShowDeleteButton="True" DeleteText="<div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</div>" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceforgvEvent" runat="server" ConnectionString="<%$ ConnectionStrings:PoliceManagerConnectionString %>"
DeleteCommand="UP_Event_Delete" DeleteCommandType="StoredProcedure" SelectCommand="UP_Event_GetList" SelectCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="EventDescription" Type="string" />
</DeleteParameters>
DataKeyNames 里面有ID和EventDescription
在存储过程中本来只用一个id的参数就可以,可是这样删除的话就会发生异常
要避免异常的发生只有两种方法:
一:把 DataKeyNames里面的EventDescription去掉,只留下一个“ID”;
在<DeleteParameters>标签里面只添加一个参数:<asp:Parameter Name="ID" Type="Int32" />
二:在存储过程“UP_Event_Delete”里面定义两个参数,再在<DeleteParameters>标签里面只添加两个参数:<asp:Parameter Name="ID" Type="Int32" /><asp:Parameter Name="EventDescription"
Type="string" />
- 2005中GridView 的DataSource中存储过程用到的参数和DataKeyNames的冲突
- GridView中DataKeyNames的应用小结
- GridView中DataKeyNames的应用小结
- GridView中DataKeyNames的应用小结
- GridView控件的DataKeyNames
- GridView的DataKeyNames属性
- GridView的DataKeyNames和DataKeys属性
- GridView 中DataKeyNames 存储数据键值
- GridView中使用DataKeyNames存储数据键值
- GridView中使用DataKeyNames存储数据键值
- GridView中使用DataKeyNames存储数据键值
- GridView 中DataSource绑定和DataSourceID绑定的区别
- 存储过程中一些用到的语句的整理
- gridveiw中DataKeyNames属性的作用
- MySql 存储过程中要用到的运算符
- GridView的DataKeyNames的一些用法
- 【转】GridView的DataKeyNames的一些用法
- C# GridView 中DataKeyNames 存储数据键值(转)
- 基础练习题(二)
- Developer10g或Oracle AS 10g配置中的问题
- 软件测试从零开始
- 软件测试工程师为何而生?
- 程序员,不要让自己做兔子(updated)
- 2005中GridView 的DataSource中存储过程用到的参数和DataKeyNames的冲突
- 程序员,不要让自己做兔子
- C#读取XML文档
- C# public和static 变量的区别
- java程序员年度最高可达18万
- test
- 常用的tar和rpm命令参数列表
- 什么是OEM服务?
- 他山之石