2014年7月13日 星期日

[RESOLVED] How do I get SqlDataSource Control parameters from a FormView Drop Down


I have a drop down in a form


                                DataSourceID="SqlLimiter" DataTextField="ShortName" DataValueField="myID">

I want to get to the selected value as a "control parameter for my SQLDataSource Query.


            SelectCommand="SELECT [myID], [ParentType], [ShortName], [IsActive] FROM [Categories] WHERE (([ParentType] = @ParentType) AND ([IsActive] = @IsActive) AND ([ParentID] = @ParentID) AND ([StoreID] = @StoreID))">







It won't work because it is "contained" within the formview container edit mode


How do I get around this?



I tried following this.


http://geekswithblogs.net/AzamSharp/archive/2006/08/27/89475.aspx


But it didn't work.


        SelectCommand="SELECT [myID], [ParentType], [ShortName], [IsActive] FROM [Categories] WHERE (([ParentType] = @ParentType) AND ([IsActive] = @IsActive) AND ([ParentID] = @ParentID) AND ([StoreID] = @StoreID))">









Simply bind it, SelectedValue = '<%# Bind("ParentId") %>' then in parameter use



oned_gk


Simply bind it, SelectedValue = '<%# Bind("ParentId") %>' then in parameter use


Hello,


I also have a problem of parameter not going through, but I guess the reason is different.


The two controls and their datasources are together, on the development machine it runs quite OK, but on an IIS server it seems the parameter stays empty. Is the syntax different ?


I tried what you say, but I am afraid I did not manage the quotes properly, which gave an error on the page.




The blog was the answer to my problem and referencing the container as parent to the child element. 
FormView2$DepartmentSelected


It wasn't working for some reason right away because of some other minor issue.


It doesn't matter if its in the same piece of code, you can't get to the parameter if it is a "child" or a "contained" object, ie, with gridview, formview without referencing that.  Shouldn't be any different between IIS and development
but practically its Microsoft code so everytime you compile it on a different machine you get different results.  So very common to see a piece of code tested working at one place not to work at all on another place. 



Maybe you need code behind


Protected Sub DepartmentSelected_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DepartmentSelected.SelectedIndexChanged
SqlCatLimiter.SelectParameters("ParentId").DefaultValue = CType(sender, DropDownList).SelectedValue
End Sub

or


    Protected Sub SqlCatLimiter_Selecting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlCatLimiter.Selecting
Dim ddl As DropDownList = CType(FormView1.FindControl("DepartmentSelected"), DropDownList)
If ddl IsNot Nothing Then
SqlCatLimiter.SelectParameters("ParentId").DefaultValue = ddl.SelectedValue
End If
End Sub







oned_gk



SqlCatLimiter.SelectParameters("ParentId").DefaultValue = CType(sender, DropDownList).SelectedValue




You know, I am afraid the DefaultValue is ignored. In fact I put one at design time to show the subcategories of the first category, but the subcategory dropdownlist stays empty. I tried to modify it as you say at the selection of a value in the category
dropdownlist, but that changed nothing.


As soon as I remove the system.data section in the Web.config, it runs jolly good on the development machine, but the server throws an exception on the page, as it does not find the provider for the database. They did not install the MySql Connector Net,
and do not seem willing to do it.


 

   

     

     

   


 



One of the big differences between the development system and propagation to IIS will be the "data".   I bet the database and data are different.  The development system probably had a hefty data set and now on IIS there is no data.  This will create bugs
and problems you didn't see before.  One of those would be default values and "null" situations.



Hello,


I found the answer the day after while reading an example in the MySqlMembershipProvider code from CodeProject.


It is very simple :



  • with SQL Server, in a SQL request code you mark a parameter with the @ character
  • with MySql, in a SQL request code you mark a parameter with the ? character.

And that is it.


My page is now online, and the parameters are very well transmitted from a dropdownlist to the other.



沒有留言:

張貼留言