我使用了sqldatasource(asp.net)的rad网格视图。我检查了自动生成更新和删除列以及自动更新和删除,但是当我点击编辑并更改了一个值然后点击更新链接按钮时没有发生任何事情......甚至没有刷新。但是,删除按钮工作正常。
我该怎么办?
这是我的代码:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1" GroupPanelPosition="Top">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="index" DataSourceID="SqlDataSource1">
<Columns>
<telerik:GridBoundColumn DataField="index" DataType="System.Int32" FilterControlAltText="Filter index column" HeaderText="index" ReadOnly="True" SortExpression="index" UniqueName="index">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="name" FilterControlAltText="Filter name column" HeaderText="name" SortExpression="name" UniqueName="name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="price" DataType="System.Int32" FilterControlAltText="Filter price column" HeaderText="price" SortExpression="price" UniqueName="price">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="subject" FilterControlAltText="Filter subject column" HeaderText="subject" SortExpression="subject" UniqueName="subject">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="exp" FilterControlAltText="Filter exp column" HeaderText="exp" SortExpression="exp" UniqueName="exp">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="link" FilterControlAltText="Filter link column" HeaderText="link" SortExpression="link" UniqueName="link">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="img1" FilterControlAltText="Filter img1 column" HeaderText="img1" SortExpression="img1" UniqueName="img1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="img2" FilterControlAltText="Filter img2 column" HeaderText="img2" SortExpression="img2" UniqueName="img2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="img3" FilterControlAltText="Filter img3 column" HeaderText="img3" SortExpression="img3" UniqueName="img3">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="img4" FilterControlAltText="Filter img4 column" HeaderText="img4" SortExpression="img4" UniqueName="img4">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConStr %>" DeleteCommand="DELETE FROM [RPtbl] WHERE [index] = @index" InsertCommand="INSERT INTO [RPtbl] ([name], [price], [subject], [exp], [link], [img1], [img2], [img3], [img4]) VALUES (@name, @price, @subject, @exp, @link, @img1, @img2, @img3, @img4)" SelectCommand="SELECT * FROM [RPtbl]" UpdateCommand="UPDATE [RPtbl] SET [name] = @name, [price] = @price, [subject] = @subject, [exp] = @exp, [link] = @link, [img1] = @img1, [img2] = @img2, [img3] = @img3, [img4] = @img4 WHERE [index] = @index">
<DeleteParameters>
<asp:Parameter Name="index" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="price" Type="Int32" />
<asp:Parameter Name="subject" Type="String" />
<asp:Parameter Name="exp" Type="String" />
<asp:Parameter Name="link" Type="String" />
<asp:Parameter Name="img1" Type="String" />
<asp:Parameter Name="img2" Type="String" />
<asp:Parameter Name="img3" Type="String" />
<asp:Parameter Name="img4" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="price" Type="Int32" />
<asp:Parameter Name="subject" Type="String" />
<asp:Parameter Name="exp" Type="String" />
<asp:Parameter Name="link" Type="String" />
<asp:Parameter Name="img1" Type="String" />
<asp:Parameter Name="img2" Type="String" />
<asp:Parameter Name="img3" Type="String" />
<asp:Parameter Name="img4" Type="String" />
<asp:Parameter Name="index" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:1)
只需将Private Sub RadGrid1_InsertCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand
RadGrid1.Rebind()
End Sub
Private Sub RadGrid1_ItemInserted(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted
RadGrid1.Rebind()
End Sub
事件调用到代码隐藏中的以下任何一种方法:
private void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
RadGrid1.Rebind();
}
private void RadGrid1_ItemInserted(object sender, Telerik.Web.UI.GridInsertedEventArgs e)
{
RadGrid1.Rebind();
}
如果您使用的是C#:
sqlcipher
希望这会有所帮助......