CPK_2011 CPK_2011 - 3 months ago 17
ASP.NET (C#) Question

Both DataSource and DataSourceID are defined on 'ctl00'. Remove one definition

I am trying to create a RadGrid with SqlDataSource declaratively and there is need to update the Grid with database records from Server side too.

The sample code is given below.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="spSelect" SelectCommandType="StoredProcedure" ConnectionString="<%$ ConnectionStrings:iTomsConnectionString %>">
<SelectParameters>
<asp:SessionParameter Name="Id" SessionField="Id" Type="Int32" />
<asp:SessionParameter Name="Name" SessionField="Name" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadGrid ID="grvUpdate" runat="server" GridLines="Horizontal"
CellPadding="0" BorderWidth="0px" EnableEmbeddedSkins="False" Skin="skn_RadGrid"
SkinsDir="|CurrentTheme|/" SkinsPath="|CurrentTheme|/"
Width="382px" CellSpacing="0">
<MasterTableView
AllowPaging="true"
PageSize="15"
EditMode="PopUp"
CommandItemDisplay="Top"
AllowFilteringByColumn="false" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="Id">

<Columns>
<telerik:GridBoundColumn DataField="Id" DataType="System.Int64" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" SortExpression="Amount" UniqueName="Amount">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn DataTextField="Reject" HeaderText="Reject" SortExpression="Reject" Text="Reject Button" UniqueName="Reject" CommandName="Reject"></telerik:GridButtonColumn>
</Columns>

<EditFormSettings>
<EditColumn InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif" CancelImageUrl="Cancel.gif"></EditColumn>
</EditFormSettings>
</MasterTableView>


</telerik:RadGrid>


How can I do Databind without the error as mentioned in the title of this Query in ASP.Net Server code as well as have SqlDataSource to retrieve/update/delete records?

The Server side code in page_load is given below

grvUpdate.DataSource = ds.Tables[0];
grvUpdate.DataBind();

Answer

I need to implement both methods simultaneously. And the solution is given below.

grvUpdate.DataSource = ds.Tables[0];
grvUpdate.DataSourceID = String.Empty;
grvUpdate.DataBind();
Comments