.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Dynamically changing SqlDataSource.SelectCommand from FormView.ModeChanged

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :ASP.Net
 

In an asp.net 3.5 web app, I have a page with the following markup/code (this is the brief version, but I believe I got all the relevant info).

<%@ Page Language="VB" AutoEventWireup="false"   %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<script runat="server">

    Private Shared FormMode As String
    Private Shared ParentSrID As Integer
    Private Shared SRRow As DataRowView
    
    Protected Sub LinkButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim button As String = GetPostBackControl(Me).ID
        Select Case button
            Case "EditButton"
                frmSR.ChangeMode(FormViewMode.Edit)
                FormMode = "Edit"
            Case "UpdateButton"
                If Not frmSR.CurrentMode = FormViewMode.Edit Then
                    Try
                        frmSR.UpdateItem(True)
                    Catch ex As HttpException
                    End Try
                End If
            Case "CancelButton" 'Cancel SR Add/Edit
                frmSR.ChangeMode(FormViewMode.ReadOnly)
        End Select
    End Sub
    
    Protected Sub frmSR_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles frmSR.DataBound
        'We want to use the current record


View Complete Post


More Related Resource Links

Mapping SqlDataSource Parameters to Formview with Multiple DataKeys

  
Hi I have:a FormView that is linked to SqlDataSource1a Repeater control (inside the formview) that is linked to SqlDataSource2Thus representing a simple "1 to many" or "parent/child" relationship in the database!SqlDataSource1 is simple in that it just retrieves a straight set of records from a table and they are displayed back in the FormView (nothing special happening there). SqlDataSource2 has parameters that  filter the contents of the repeater based on the record that is shown in the Formview. This would normally be simple enough to set up by setting the parameter to the formview.selectedvalue property.HOWEVER - THE PROBLEM ARISES...The formview has multiple DataKeyNames because the table that the SqlDataSource1 links to has a compound key. So to filter the Repeater correctly SqlDataSource2 needs to map 3 parameters to 3 data key values in the formview.Any ideas how to do this?I've tried setting the SqlDataSource2 parameters to:<SelectParameters>   <asp:ControlParameter ControlID="FormView1" Name="Parameter1" PropertyName="DataKey(0)" />   <asp:ControlParameter ControlID="FormView1" Name="Parameter2" PropertyName="DataKey(1)" />   <asp:ControlParameter ControlID="FormView1" Name="Parameter3" PropertyName="DataK

Mapping SqlDataSource Parameters to Formview with multiple DataKeys

  
Hi I have:a FormView that is linked to SqlDataSource1a Repeater control (inside the formview) that is linked to SqlDataSource2Thus representing a simple "1 to many" or "parent/child" relationship in the database!SqlDataSource1 is simple in that it just retrieves a straight set of records from a table and they are displayed back in the FormView (nothing special happening there). SqlDataSource2 has parameters that  filter the contents of the repeater based on the record that is shown in the Formview. This would normally be simple enough to set up by setting the parameter to the formview.selectedvalue property.HOWEVER - THE PROBLEM ARISES...The formview has multiple DataKeyNames because the table that the SqlDataSource1 links to has a compound key. So to filter the Repeater correctly SqlDataSource2 needs to map 3 parameters to 3 data key values in the formview.Any ideas how to do this?I've tried setting the SqlDataSource2 parameters to:<SelectParameters>   <asp:ControlParameter ControlID="FormView1" Name="Parameter1" PropertyName="DataKey(0)" />   <asp:ControlParameter ControlID="FormView1" Name="Parameter2" PropertyName="DataKey(1)" />   <asp:ControlParameter ControlID="FormView1" Name="Parameter3" PropertyName="DataK

sqldatasource with Inner Join SelectCommand....

  
I have a gridview with a sqldatasource with SelectCommand as below:"SELECT DISTINCT pr1.ID, pr1.Candidate_Code, pr1.Desc2 AS Name_EN, pr2.Desc2 AS Name_CN FROM Table1 pr1 INNER JOIN Table1 pr2 ON pr1.Candidate_Code = pr2.Candidate_Code AND pr1.Stat1=pr2.Stat1 AND pr2.Desc1 = 'NAMA (CINA)' WHERE pr1.SESSIONS = @Sessions and pr1.DUN = @Dun AND pr1.Stat1 = 'M' AND pr1.Desc1 = 'NAMA (ENG)'" Hw can set the UpdateCommand to update pr1.Candidate_Code? I have tried "UPDATE SPR_Candidate_Profile2 SET Candidate_Code = @Candidate_Code WHERE ID = @ID AND Candidate_Code = @Candidate_Code" but it's not workling.....

SqlDataSource, FormView, and Update with stored procedure in code behind

  
Hello, Using a FormView with a SqlDataSource, I'm attempting to Update data by calling a stored proc in code behind. I was having trouble getting parameters using Update Parameters in the SqlDataSource, but found a working solution by coding the parameters. The problem now is I'm getting an "Updating is not supported by data source 'XYZ' unless UpdateCommand is specified'. I saw some previous posts on the forums, but didn't find them very enlightening. 

Dynamically Add Row To SqlDataSource

  

I'm using a SqlDataSource to get the possible values for a drop down list however the first option must be "None" and that will not be returned by the query. How do I dynamically add this row to the SqlDataSource? I tried to just add a ListItem for the "None" option to my DropDownList but it gets removed by the SqlDataSource data binding.


Modifying the SqlDataSource SelectCommand prior to loading a page

  

I have a SqlDataSource setup in the markup on my page. After some new requirements, I am trying to find a way to modify the SelectCommand before the data is filled for the first time. The SelectCommand below will now be used by default since we'll always have the first param. I am faced with a need to modify the SelectCommand though, adding a second session parameter along with it. I tried to override the OnInit method but it didn't seem to help...it still used the default query. Is there a best way to accomplish this? Here is the section of markup I am referring to:

    <asp:ScriptManager ID="ScriptManagerCustomerMaintenance" runat="server" EnablePageMethods="true"></asp:ScriptManager>
    <asp:SqlDataSource ID="SqlDataSourceHD" runat="server"
        ConnectionString="<%$ ConnectionStrings:HDOracleConnectionString %>"
        ProviderName="<%$ ConnectionStrings:HDOracleConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM Customer WHERE (HOME_PHONE=:HOME_PHONE)"
        UpdateCommand="UPDATE Customer SET CustomerEID=:Cu

how to change selectcommand in sqldatasource

  


hi there, i have an SQLdatasource in my page
i was trying to modify it as:
SQL.SelectCommand = "Select * from " + TXT_Tabella.Text;
because i want update dinamically my sql server tables

but ,every time i am going to sort, or change page
the selectCommand returns as before!!!

viewState is true!
how can i have an SQLdatasource dinamyc by tableName?
and how this problem occurs?


Dynamically changing the Style of TreeViewItem

  

Hi,

I am currently setting the style to the Treeview control inside Treeview.Resources which works fine. I need to change the Style dynamically when user changes selection in another control. Any thoughts on how this can be done?

Here is my current working code.

<TreeView Name="NavigationPaneTreeView" SelectedItemChanged="NavigationPaneTreeViewSelectedItemChangedEventHandler"

 

ItemsSource="{

Dynamically Changing ImageUrl in HyperLink control

  

Hey guys,

C#/.net newb alert. ;)


I'm writing a script and need help with being able to modify the ImageUrl property in a HyperLink control from the code behind page. It is meant to dynamically show an image.


I just need to know the correct format of the code behind to get this to work.


Thanks


Changing data item value Repeater dynamically

  

How do i dynamically change the value of dataitem in repeater control(.net 2.0,VS 2005)..i have repeater something like this :
<asp:Repeater ID="rptGameInfo" runat=server OnItemDataBound="itemDataBound_rptGameInfo"  >
<HeaderTemplate >

</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lblLoc" runat=server Text="Location:" ></asp:Label><%# Eval("GAME_LOCATION")%><br />
</ItemTemplate >
</asp:Repeater>

and it shows the result like this:
location:"Select"

If location is "Select" i want to change it to "n/a". So i am trying to capture it in itemDataBound even something like this

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                DataRowView row = e.Item.DataItem as DataRowView;
                string location = row["GAME_LOCATION"].ToString();

                if (location == "Select"

dynamically changing points in a PathGeometry

  

I have a PathGeometry that is initially set with points captured from inkCanvas Strokes, I want to iterate through them & translate the points to properly display on a geodetic map - how would I modify the points dynamically so it would be translated to the map control?

Thanks


Dynamically bind to often changing database

  

Hi,

Please point me to the right forum if this is not correct - I do appreciate it :-)

At work we have a database that needs a table maintenance utility written in c#/aspx/webforms. The database has about 45 tables and that could change fairly frequently.

The utility needs to present the user with a drop down of all the tables in the database, (ok - easy so far. I can get this dynamically from the database to allow for addition/deletion of tables). The user chooses a table name and is presented with the data in the table. The user can edit the data, delete or insert rows, page through the data, etc. I am guessing this is a gridview.

I can get the columns for the selected table name dynamically from the database too, but I do not seem to be able to write a generic page that uses code to bind the gridview to the data and lets the user page, insert or delete rows, etc.

In the designer a sql datasource on non-changing tables this would be easy. (Point the sds at the table, write a couple of stored procedures to add/delete/select rows, etc and the job is done).

What I don't seem to be able to do is write a generic page that will cope with dynamic binding of the grid to the database. i want to write a page that is fairly 'decoupled' from changes in the database but will still be able to provide a useful table-maintenance type tool.


Changing the graphics on the home page of a SharePoint site

  
When you create a site in Microsoft Windows SharePoint Services by using the default Team Site template, the home page includes two default graphics. A Windows SharePoint Services graphic appears in the body of the page, and a picture of a house in a circle appears near the site title. You can change these graphics to customize your site. Changing the smaller graphic requires a Windows SharePoint Services compatible Web page editor

Dynamically Create Controls in ASP.NET by Using Visual C# .NET

  
This article demonstrates how to dynamically create a control for an .aspx page. The sample project does the following:
Creates two TextBox controls.
Verifies that the contents (TextBox.text) and the attributes of the TextBox are saved across posts to the server.
Illustrates handling events that are posted by a dynamically-created control

Dynamically Create Controls in ASP.NET with Visual Basic .NET

  
This step-by-step article describes how to dynamically create controls for an ASPX Web page.

The sample project does the following:
It creates two TextBox controls.
It verifies that the TextBox contents (TextBox.text) and attributes are saved across posts to the server.
It describes how events that are posted by a dynamically created control are handled.

Convert English to Arabic number without changing any regional settings in .net

  
Well, most applications that I worked with was multilingual that supports English UI and Arabic UI.

And one of the major issue that we have faced is displaying Arabic numbers without the need of changing the regional settings of the PC.

So the code below will help you to display Arabic number without changing any regional settings.

dynamically adding sql server columns based on number of files in fileuploader

  

I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.

 

I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!

 

Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")

objConn.Open()

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend