Forms Data Controls :: Both DataSource And DataSourceID Are Defined On 'DataList1'?
Nov 9, 2010
I receive the error (Both DataSource and DataSourceID are defined on 'DataList1'. Remove one definition) in the following code. Could anyone help me sort this out. I do not have anything named DatasourceID that I can find.
[code]...
I'm working on two gridviews , each one binded to an sqldatasource object,when I want to modify the 2nd gridview (DataSource=DataTable) an error fired !Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
{"Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition."}
view on browser application
Line 33: Line 34: GridView1.DataSource = dtLine 35: GridView1.DataBind()Line 36: End SubLine 37:
This is an my vb code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Me.IsPostBack Then Me.BindGrid() End If End Sub Private Sub BindGrid()
And i get error like this: Both DataSource and DataSourceID are defined on 'Grid_Goster'. Remove one definition. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Both DataSource and DataSourceID are defined on 'Grid_Goster'. Remove one definition. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using And in my .cs file there is code like this.
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Grid_Goster.DataSource = dr; Grid_Goster.Visible = true;
i think this code works correctly. How can i solve this DataSource and DataSourceID problem?
I'm getting the following error, ever since I moved my DataTable to a different function. Both DataSource and DataSourceID are defined on 'TestView'. Remove one definition.By all means if you have tips on style / standards, I welcome that as well, I am very new to aspx coding. Any idea what could be causing this? It wasn't happening before when it wasn't its own function. Is it a local variable problem?
Here's the code for the code that binds and is highlighted in the error:
testDAO tda = new testDAO(); DataTable testTable = new DataTable("TestView"); testTable = tda.GetTestTable(); TestView.DataSource = testTable; TestView.DataBind();
Here's the code for the GetTestTable():
public DataTable GetTestTable() { DataTable testTable = new DataTable("TestView");[code]....
I have connected listview by using datasourceid that means by using "sqldatasource1" now i want to change value of listview at run time according to search so for that i am using datasource at codebehind. but it give an error
"listview have already bind with datasourceid you can not bind it with datasource"
I successfully bind ListView DataSourceID to ObjectDataSource but it binds only initially on Page_Load event. When I want to bind another data through a Button_Click event, the new data doesn't bind.
aspx code:
[Code]....
Codebehind:
[Code]....
On Page_Load, I get result:
A1 <hr /> T1 A2 <hr /> T2 A3 <hr /> T3
When I Button1_Click, nothing happens, no error, no any more results and _airLineData is 53 records, not 3 records (A1T1 to A3T3) I want the binding to be with DataSourceID to ObjectDataSource (not through DataSource property and control.DataBind() method)
i am trying to export a table from access database to excel sheet but i am facing error saying Type 'System.Data.OleDb.OleDbCommand' is not defined.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and SettingsUSERDesktopD0605data.accdb") AccessConn.Open() 'New sheet in Workbook Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [Excel 8.0;DATABASE=C:Documents and SettingsUSERDesktopD0605data1.xlsx;HDR=NO;].[Sheet1] from [Table1]", AccessConn) AccessCommand.ExecuteNonQuery() AccessConn.Close() End Sub End Class
Instead of using DataSourceID I have a DataSource built up in codebehind that I bind to the reorderlist. I have set "PostBackOnReorder=True" but how do I update the database on that postback? How do I collect the new order and then save it to the database?
I have a couple different sqldatasources on an asp.net page that all fire the same onSelecting Event Handler. The reason for this is because the same code in the event handler can be applied to all datasources (which essentially generates filters in the queries dynamically). However, now I have another datasource that can still use most of the code, but needs to be handled slightly differenty. I could do this very easily if I could reference the datasource's ID that is firing the event (which I've tried), but this doesn't seem to be possible. Here is what I initially attempted to do:
protected void sdsTable_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { SqlDataSource sds = sender as SqlDataSource; string dsID = sds == null ? "" : sds.ID; if (dsID == "aDataSourceID") { //do this } else { //do that } //more code }
This didn't work because sender is of type SqlDataSourceView and trying to cast sender as SqlDataSource returns null. So, I changed it to SqlDataSourceView:
protected void sdsTable_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { SqlDataSourceView sds = sender as SqlDataSourceView; string dsID = sds == null ? "" : sds.Name; //Tried Name property because ID isn't available if (dsID == "aDataSourceID") { //do this } else { //do that } //more code }
But this still doesn't work. SqlDataSourceView doesn't seem to have a property available that gives the datasourceID of the datasource that is currently firing the event. There is a SqlDataSourceView.Name property, but this is something different. Does anyone know if it is possible to get the ID of the DataSource firing the Selecting event when that event is being handled? If so, can you provide an example on how to do this?
I have a strange problem. I am adding a LinqDatasource object, and set the context:
[Code]....
Then I get this error:The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I am trying to create a type of table on sql 2008. The following sql fails saying Incorrect syntax near the keyword 'AS'. what i am doing wrong as this looks fine to me.
I have a database that tells me what contract is in effect on specific streets but between mile marker values.
For example, Main Street is 10 miles long. Contract ABC123 applies to miles 0 - 4.9, and contract 999555 applies to miles 5-10.
My user will enter the street name and mile value into textboxes, and the results will be displayed in a gridview.
Getting the Street name portion of the query is working fine, it is this mile value that is confusing me.
In my table I have StreetName for the name of the street, and for the mile range of the street the table has BegMile (beginning value) and EndMile (ending value).
How do I get the correct answer back when my user is entering a value between BegMile and EndMile?
I know that the problem is my field having NULL values. However, I don't know how to have it process the code even if the field have nullshere's my code:
My Problam is on Capturing Text Box and Dropdown seleted itam from grid view i create a gridview with Empty DB binding using [URL] this senirio. I only used setinitional value() function and called its in page load as discribed in above lonk. insted of adding New record Button i callled a java scrit code discribed below. and i also create a button (SAVE) to capture a value intered in text box . On this button click event i try to capture a textbox and dropdown value like
for (int i = 0; i < Gridview1.Rows.Count; i++) { DropDownList sen_to1 = (DropDownList)Gridview1.Rows[i].Cells[1].FindControl("DD_sento_org"); TextBox Add_to1 = (TextBox)Gridview1.Rows[i].Cells[2].FindControl("Txt_addto"); int Add_to = Convert.ToInt32(sen_to1.SelectedValue); String Addd_to = Add_to1.Text; }
but its not working i can not go inside loop.
<script type='text/javascript' language='javascript'> function AddNewRecord(keyCode, obj) { if (window.event.keyCode==13 )var grd = document.getElementById('Gridview1'); var tbod=grd.rows[0].parentNode; var newRow=grd.rows[grd.rows.length - 1].cloneNode(true); cleanUpInputs(newRow); tbod.appendChild(newRow); } } return false ;
I have impelemented my own mvc pattern to my website , when I add desired type for my ObjectDataSource pointing to the controller class although GridView refreshes schema in designer just fine I get an error in runtime saying : "No parameterless constructor defined for this object." which is self explaining but I wonder why does it happening because I've used this pattern once and didn't have that issue , here is the bit of code that is causing this issue , what to do to keep my mvc and make it work :
i created a user control and place a button on it.i drag dropped the user control on a aspx page and wrote the grid load and button clicks in the
user control.now i got a requirement to use the same user control grid and button to again use on the same page.however the data populated will be different and the button click functionality will be different.how can i reload the different data on the second grid as i had already wrote the code in the first one