Get The DatasourceID Of The Datasource That's Firing The OnSelecting Event?
Mar 11, 2011
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?
View 1 Replies
Similar Messages:
Jan 27, 2010
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?
View 1 Replies
Jan 26, 2011
But it's different situation on gridview.
<asp:GridView ID="Grid_Goster" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource3" ForeColor="#333333" GridLines="None"
Height="144px" Width="316px">
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:SqlServerCstr %>"
SelectCommand="SELECT * FROM [AVUKAT]"></asp:SqlDataSource>
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?
View 3 Replies
Nov 5, 2010
How do we remove either DataSource or DataSourceID from FormView2?
Code behind reads:
[Code]....
View 3 Replies
Jan 26, 2011
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]....
List view in aspx file:
<asp:ListView ID="TestView" runat="server">
<ItemTemplate>
<tr id="row" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "row" : "altrow" %>'> [code]....
View 2 Replies
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]...
View 2 Replies
May 7, 2015
When i click for bug an aplication.
it's always show this a notification
{"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()
[Code] .....
View 1 Replies
Jul 23, 2010
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.
View 4 Replies
Jan 22, 2010
I'm sure I'm missing something extremely obvious here, but at this point I can't see it so I need the help.Anyway, I've got a repeater inside of an UpdatePanel. As of right now, I've stripped it down to this, just to try and isolate the problem:
[Code]....
Whether I add the handler during itemdatabound or I add the handler within the repeater itself, it doesn't seem to matter...the event itself doesn't fire. The AutoPostback itself seems to fire, but the event itself doesn't.
View 3 Replies
Jun 8, 2010
Up till the moment I can not understand why the "SqlDataSource_NewAccount_Inserting" event of the formview's SqlDataSource is not firing!
The code inside the event handler is not executed, even the debugger does not stop on break points inside the "SqlDataSource_NewAccount_Inserting" function!
Here is my code:
[Code]....
I am using VS2010 and target .NET Framework 3.5.
View 9 Replies
Oct 13, 2013
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"
what should i do for solving my requirement.
View 1 Replies
Mar 1, 2011
I have a gridview called gvResults. In the gvResults_RowEditing event I add a row below the one selected. In that new row, which spans all columns, I insert a user-control. There are two buttons and some textboxes in the user control.
My problem is that when I click one of the user-control buttons it never gets to the button event handler, I think because the user control is not recreated on the page postback. How can I have the user-control events fire before the parent page events fire?
I tried using an update panel, but I still get the parent posting back before the user-control events.
View 3 Replies
May 8, 2010
I am facing one strange problem,I have a gridview in which the last two columns have checkboxes and on those checkboxes click event I am doing some database operations.I also have one checkbox that is outside the gridview which actually shows or hides some of the gidview columns.This was all working well but now I have shifted that grid to a user control because I have to use it in two pages.The problem now is,When the page first loads and I click the check box or any control in the page that is outside the grid then it works perfectly.But once I click any of the check box within grid view column then its behavior chages, now even if I click the checkbox that is outside the grid then also the checkbox_CheckedChanged event of the checkbox that is whithin gridview is fired.That checkbox event then behaves something like a page_load event that is called for every page load and for every event with in the page after it is called once.
View 3 Replies
Sep 10, 2010
I have a page containing a datagrid, which works. On that page I have a button which is supposed to trigger a download of the data from the datagrid in Excel format. However, the button isn't firing the event. The C# code-behind I have is:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using umbraco;
namespace MyDataExport
{
public partial class DataExport : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.DataSource = BindData();
GridView1.DataBind();
[Code....]
View 1 Replies
Jul 22, 2010
I have a grid view within that i have child gridview,one coloumn of child gridview is bound to check box all thease are in update panel,
i have made checkbox autopostback="true",but check_changed() event is not firing
View 1 Replies
Feb 10, 2011
I am using Ext.Net and I have a problem.
I am creating dynamic buttons. It is working but if i click, the button event is not working.:(
My code:
foreach (var events in eventsInformation)
{
Ext.Net.Button btn = new Ext.Net.Button();
btn.ID = events.EvtId.ToString();
btn.Text = events.EvtName;
btn.Click += new EventHandler(Tickets_click);
ViewPort1.Controls.Add(btn);
}
View 2 Replies
Apr 4, 2010
I am using asp:menu.In this asp menu,on clicking menu item,I want to get the menuitem,and its parent.I tried to use menuitemclick event.But menuitemclick event is not firing on clicking menu item.
View 1 Replies
Mar 21, 2010
In tab container let say I have two tabs [Tab1 & Tab2] Tab1 has 2 text box with required field validator Tab2 has 3 text box with required field validator Now even if I am filling all the text boxes in the TAB1, it is not allowing me to postback. [because TAB2 text boxes are still empty] & When I am filling all the textboxes [Both Tab1 & Tab2], button is firing correctly. I mean user has to fill details for the TAB1 & can submit the details. At that Time I don't want TAB2 validations to work.
View 1 Replies
Jan 6, 2011
I've stepped through the code and verified this action. It gets to the end sub and just loops again. Also does it on the production server in IE and Chome (that's all I've tried). Here is the button definition on the actual ASP page:
[Code]....
It goes through the code, sends me an email, gets to End Sub, then loops right back to the top of the sub and goes through the whole thing again, sending me a duplicate email, then exiting normally and sending them to the About page. This is the only code in the aspx.vb besides the class def and inherits statement.
View 2 Replies
Nov 4, 2010
I have a gridview with rows of data and a group of radio buttons for each row that can be selected. But when selected the event never fires for the radio dropdown.... why?
[code]....
View 2 Replies
Apr 6, 2010
when the user comes out of a texbox, i need to read the text entered in the textbox.
I tried using the textchanged event. But it is not firing when i move out of the textbox.
View 7 Replies
Jul 23, 2010
I put a break point at the protected void Page_Load(object sender, EventArgs e) method of my master page, but when i start the site it does not hit that break point.
Why is the event not firing? I would like to use this event along with others such as the Init event in order to check to see if the session has expired everytime a page loads...
View 4 Replies
Mar 1, 2011
I have a GridView, which features a a checkbox on each row (in a template field), where it calls a method upon checked changed (well, when they click submit - no auto post back)
My problem is, the checked change refuses to fire more than once - if I just change the check state of one checkbox in the grid, it works fine. More than one and it only fires the event once.
EDIT: Bit of code:
<asp:CheckBox ID="chkIncludedLocal" runat="server" Checked='<%# Bind("Included") %>'
Enabled="true" OnCheckedChanged="chkIncludedLocal_CheckedChanged" />
And in the event, I put a breakpoint right at the top to see how many times it fires
View 1 Replies
Jun 8, 2010
The OnSelectedIndexChanged event is not firing for my dropdown box. All forums I have looked at told me to add the AutoPostBack="true", but that didn't change the results.
HTML:
[code]....
View 2 Replies
Sep 23, 2010
In my web form I have a Textbox control. The TextChanged event of the Textbox is not triggering.
AutoPostBack is set to true What could be the reason for this?Here is the code:
protected void Textr_TextChanged(object sender, System.EventArgs e)
{
}
<asp:TextBox ID="Textr" TabIndex="10" Style="z-index: 117; left: 500px;
position: absolute; top: 158px" runat="server" Height="22px" Width="180px" MaxLength="50"
AutoPostBack="True" CausesValidation="true" OnTextChanged="Textr_TextChanged"
></asp:TextBox>
View 4 Replies