Quote:
error:Invalid OperationException was unhandled by usercode
Both DataSource and DataSourceID are defined on 'DetailsView1'. Remove one definition.
The Exception is quite clear.
If you look at your code, it becomes more clear.
In aspx page...
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="2" DataKeyNames="JobID" DataSourceID="SqlDataSource2"
ForeColor="Black" GridLines="None" Height="50px" Width="300px"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px">
In .aspx.cs page...
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("CompanyName"), new DataColumn("Designation") });
dt.Rows.Add("NIIT", "programmer");
dt.Rows.Add("annvision", "Webdesigner");
dt.Rows.Add("softtech", "designer");
dt.Rows.Add("Mahad", "Programmer");
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
}
}
You have to delete one as it is conflicting and can't decide which
DataSource
to assign to
DetailsView
.