我使用的GridView绑定到对象列表而不是直接SQL查询。如果工作的人口,那么更新。我已手动为此gridview生成插入,这也正常。 当尝试从gridview运行delete命令时,正在调用正确的方法,但是没有填充任何参数。唯一需要的参数是@ID但是,阅读其他帖子,一般修复一直是添加所有参数,但仍无济于事。
$Username = Domain\username";
$Password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($Username, $Password)
$session = new-pssession -computername 'serverName' -credential $cred
Invoke-Command -Session $session -ScriptBlock {copy-Item -Path $($args[0]) -destination $($args[1])} -argumentlist $_sourcepath,$_destinationPath ;
数据源如下,其他工作方法。只是删除方法不会填充任何参数。
<asp:GridView ID="GridViewBands" runat="server" AutoGenerateColumns="False" DataSourceID="BandsDataSource" CellPadding="4" ForeColor="#333333" GridLines="None" ShowFooter="True" Width="1375px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField HeaderText="AgencyID" SortExpression="AgencyID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="80px" Text='<%# Bind("AgencyID") %>' ReadOnly ="true"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TextBox1" runat="server" ErrorMessage="there is an error?" Text="*`"></asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Insert" Text="Add New Line" />
<asp:TextBox ID="newAgencyID" runat="server" Width="80px"></asp:TextBox>
<br />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("AgencyID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TypeID" SortExpression="TypeID">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Width="80px" Text='<%# Bind("TypeID") %>' ReadOnly ="true"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newTypeID" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Width="80px" Text='<%# Bind("TypeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CompanyID" SortExpression="CompanyID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Width="80px" Text='<%# Bind("CompanyID") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newCompanyID" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("CompanyID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Office" SortExpression="Office">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Width="80px" Text='<%# Bind("Office") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newOffice" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Office") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SequenceID" SortExpression="SequenceID" >
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Width="80px" Text='<%# Bind("SequenceID") %>' ReadOnly ="true"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newSequenceID" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("SequenceID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minimmum" SortExpression="Minimmum">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Width="80px" Text='<%# Bind("Minimmum") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newMinimum" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Minimmum") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Capped" SortExpression="Capped">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Width="80px" Text='<%# Bind("Capped") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newCapped" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Capped") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fixed" SortExpression="fixed">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Width="80px" Text='<%# Bind("fixed") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newFixed" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("fixed") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Flat" SortExpression="Flat">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Width="80px" Text='<%# Bind("Flat") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newFlat" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Flat") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SequenceLimit" SortExpression="SequenceLimit">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Width="80px" Text='<%# Bind("SequenceLimit") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newSequenceLimit" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("SequenceLimit") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rate" SortExpression="Rate">
<EditItemTemplate>
<asp:TextBox ID="TextBox11" runat="server" Width="80px" Text='<%# Bind("Rate") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newRate" runat="server" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Rate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ActiveFrom" SortExpression="ActiveFrom">
<EditItemTemplate>
<asp:TextBox ID="txtActiveFrom" runat="server" Width="200px" Text='<%# Bind("ActiveFrom") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newActiveFrom" runat="server" Width="200px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblActiveFrom" runat="server" Text='<%# Bind("ActiveFrom") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ActiveTo" SortExpression="ActiveTo">
<EditItemTemplate>
<asp:TextBox ID="txtActiveTo" runat="server" Width="200px" Text='<%# Bind("ActiveTo") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newActiveTo" runat="server" Width="200px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblActiveTo" runat="server" Text='<%# Bind("ActiveTo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" SortExpression="ID">
<EditItemTemplate>
<asp:TextBox ID="txtID" runat="server" Width="80px" Text='<%# Bind("ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
我尝试手动填充正在使用的参数类似于下面的内容,但是我无法找到基于&#39;选择&#39;来填充参数的方法。删除行。
<asp:ObjectDataSource ID="BandsDataSource" runat="server" SelectMethod="SelectBands" TypeName="App_Code.Billing+BillingBand" UpdateMethod="UpdateBands" DeleteMethod="RemoveBand" InsertMethod="AddNewBand">
<SelectParameters>
<asp:Parameter Name ="AgencyID" Type ="Int64" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="AgencyID" Type="Object" />
<asp:Parameter Name="TypeID" Type="Object" />
<asp:Parameter Name="CompanyID" Type="Object" />
<asp:Parameter Name="Office" Type="Object" />
<asp:Parameter Name="SequenceID" Type="Object" />
<asp:Parameter Name="Minimmum" Type="Object" />
<asp:Parameter Name="Capped" Type="Object" />
<asp:Parameter Name="fixed" Type="Object" />
<asp:Parameter Name="Flat" Type="Object" />
<asp:Parameter Name="SequenceLimit" Type="Object" />
<asp:Parameter Name="Rate" Type="Object" />
<asp:Parameter Name="ActiveFrom" Type="Object" />
<asp:Parameter Name="ActiveTo" Type="Object" />
<asp:Parameter Name="ID" Type="Object" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="AgencyID" Type="Object" />
<asp:Parameter Name="TypeID" Type="Object" />
<asp:Parameter Name="CompanyID" Type="Object" />
<asp:Parameter Name="Office" Type="Object" />
<asp:Parameter Name="SequenceID" Type="Object" />
<asp:Parameter Name="Minimmum" Type="Object" />
<asp:Parameter Name="Capped" Type="Object" />
<asp:Parameter Name="fixed" Type="Object" />
<asp:Parameter Name="Flat" Type="Object" />
<asp:Parameter Name="SequenceLimit" Type="Object" />
<asp:Parameter Name="Rate" Type="Object" />
<asp:Parameter Name="ActiveFrom" Type="Object" />
<asp:Parameter Name="ActiveTo" Type="Object" />
<asp:Parameter Name="ID" Type="Object" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="AgencyID" Type="Object"/>
<asp:Parameter Name="TypeID" Type="Object" />
<asp:Parameter Name="CompanyID" Type="Object" />
<asp:Parameter Name="Office" Type="Object" />
<asp:Parameter Name="SequenceID" Type="Object" />
<asp:Parameter Name="Minimmum" Type="Object" />
<asp:Parameter Name="Capped" Type="Object" />
<asp:Parameter Name="fixed" Type="Object" />
<asp:Parameter Name="Flat" Type="Object" />
<asp:Parameter Name="SequenceLimit" Type="Object" />
<asp:Parameter Name="Rate" Type="Object" />
<asp:Parameter Name="ActiveFrom" Type="Object" />
<asp:Parameter Name="ActiveTo" Type="Object" />
<asp:Parameter Name="ID" Type="Object" />
</UpdateParameters>
</asp:ObjectDataSource>
但是这会返回一个NULL引用异常。
这是删除方法,例如,update和add方法格式相同,并且工作正常。
Protected Sub BandsDataSource_Deleting(sender As Object, e As ObjectDataSourceMethodEventArgs) Handles BandsDataSource.Deleting
e.InputParameters("ID") = GridViewBands.SelectedRow.ID.ToString()
End Sub
答案 0 :(得分:0)
必须在GridView中添加onRowDeleting参数,该参数必须设置用于删除的变量的默认值。
<asp:GridView ID="GridViewBands" runat="server" AutoGenerateColumns="False" DataSourceID="BandsDataSource" OnRowDeleting="test" CellPadding="4" ForeColor="#333333" GridLines="None" ShowFooter="True" Width="1375px">
<AlternatingRowStyle BackColor="White" />
<Columns>
Protected Sub test(sender As Object, e As GridViewDeleteEventArgs)
Dim thisID As Integer = e.Values(13)
BandsDataSource.DeleteParameters("ID").DefaultValue = thisID
BandsDataSource.Delete()
BandsDataSource.DataBind()
BandsDataSource.Dispose()
End Sub