Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2007, 02:36 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default Problems with "SelectedValue" in Control Parameter

I have seen, in several sites, where someone uses the "SelectedValue" PropertyName inside the ControlParamater within a SelectParameter of a Gridview. I have seen this used when the CommandName of the Gridview is customer (ie. "Addresses"). However, I can never get this to work when the CommandName of the control is anything other than "SELECT"

Take a look at my page:

<%@ Page Language="VB" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="false" CodeFile="addawards.aspx.vb" Inherits="Admin_addawards" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" DataKeyNames="AwardID" >
        <Columns>
            <asp:CommandField ShowDeleteButton="True" />
            <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
            <asp:BoundField DataField="AwardID" HeaderText="AwardID" SortExpression="AwardID" />
            <asp:ButtonField CommandName="editplaces" Text="Edit Places" />
        </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Searing.SunArtSite.BO.Award"
        DeleteMethod="DeleteAward" SelectMethod="GetList"
        TypeName="Searing.SunArtSite.Bll.AwardsManager"></asp:ObjectDataSource>
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="ODSPlaceList">
        <Columns>
            <asp:BoundField DataField="PlaceID" HeaderText="PlaceID" SortExpression="PlaceID" />
            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
            <asp:BoundField DataField="AwardID" HeaderText="AwardID" SortExpression="AwardID" />
            <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
        </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ODSPlaceList" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetPlaceListPerAward" TypeName="Searing.SunArtSite.Bll.PlaceManager">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
</div>

</asp:Content>


Please notice that the command name is "editplaces"
Although this will trigger the codebehind RowCommand, it will not put the selectedvalue of the Grid in. I assume because the only way to trigger this is with the command being "SELECT"??

Is there a way to programatically trigger a "SELECT"? The reason I ask is that I am trying to set up several different buttonfields to basically trigger different controls.

The code behind page:

Imports Searing.SunArtSite.BO

Partial Class Admin_addawards
    Inherits System.Web.UI.Page




    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
        Select Case e.CommandName.ToLower
            Case "editplaces"
                GridView1.DataBind()
        End Select
    End Sub
End Class


Thanks,
Rob


 
Old July 10th, 2007, 07:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

I don't understand your problem.. the only thing that editplaces do is to rebind the gridview.. what values you want to put in the table???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old July 10th, 2007, 09:24 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

I apologize, I should have deleted this topic, as I noticed it was very fragmented, I tried to clean up what I am trying to do and re-posted at:

http://p2p.wrox.com/topic.asp?TOPIC_ID=62738

I had forgotten I didn't delete this and will try-but don't think I can after someone has replied.

Basically--I'm trying to figure out how to have two different controls both use the same Gridview as their SELECT Control Parameter. In the Gridview, I would have two different buttons that would contain two different CommandNames--depending upon which one was clicked in the Gridview, the respective "child control" would populate.

So, each "child" control would have it's own ObjectDataSource--each with a SELECT Control Parameter--pointing to the Gridview. The problem is that the only "PropertyName" I have seen used in a control parameter is "SelectedValue". The problem with this..is this is only assigned if the parent gridview's "SELECT" command is clicked--not a custom CommandName. So--I'm trying to figure out how to have a custom CommandName to trigger the SELECT Control parameter in the two child controls (both FormViews)

That make sense? If so--I'll just delete the topic referenced above that nobody has replied to yet.

Thanks for your time!
Rob

 
Old July 10th, 2007, 09:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Still trying to figure out what is your problem.. since what you are telling look that will work without a problem from codebehind.. the only problem is in your code that you are rebinding the grid and not the formview...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old July 10th, 2007, 10:26 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Sorry---all the code was actually in the link I provided.

My problem is I only know one way to use a Control parameter--using the "SelectedValue" for PropertyName.

The problem with this is it only works when you click something in the parent control that triggers a SELECT.

I am trying to figure out how you can tie a Control Parameter to a control with something other than "SelectedValue".

Here's a dummied down version of my problem....

I have a gridview:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" DataKeyNames="AwardID" >
   <Columns>
      <asp:CommandField ShowDeleteButton="True" />
      <asp:BoundField DataField="Location" HeaderText="Location"/>
      <asp:BoundField DataField="AwardID" HeaderText="AwardID"/>
      <asp:ButtonField CommandName="editplaces" Text="Edit Places" />
   </Columns>
</asp:GridView>

Now..notice the buttonfield with CommandName "editplaces"

Now I have a formview that has the following objectDataSource:

<asp:ObjectDataSource ID="ODSPlaceList" runat="server"
        SelectMethod="GetPlaceListPerAward" TypeName="Searing.SunArtSite.Bll.PlaceManager">
<SelectParameters>
   <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

Now..notice the PropertyName is "Selected Value"--and points to the Gridview1.

When I click on the button with commandname editplaces, FormView1 will never populate because it's controlparameter is Gridview's "SelectedValue"..well..clicking on the button didn't trigger a "Select" command..it triggered a "editplaces" command.

What I would like to do is, upon clicking a button in the gridview--have a different control bind to the datakey of that gridview's row.

perhaps this is somethign really simple, and I just don't understand how events happen...but I'm just trying to figure out how to change the PropertyName of the Formview's ObjectDataSource from SelectedValue--to something else that will capture an event from the Gridview from clicking on a button.

Does that make sense?

Thanks--and sorry if I'm not making this clearer.
Rob


 
Old July 11th, 2007, 09:30 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Well, I finally figured this out with the help of a friend, and it's rather easy.

You can create a buttonfield on the main Gridview and use a custom commandname, for example, use "editplaces"

Then, in the code behind page, tie into the RowCommand Sub:

Protected Sub GridView1_RowCommand(ByVal sender as Object, ByVal e as System.web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RoCommand

Select Case e.commandName.ToLower

  Case "editplaces"
    Dim SArg as String = Gridview1.DataKeys(e.CommandArgument).Value.ToStri ng
    Dim parm1 as Parameter = ObjectDataSource1.SelectParameters(0)
    parm1.DefaultValue = SArg
End Select


SO--this way, you can have multiple buttonfields in the main Gridview-each with it's own custom Command and then simply use the Case to bind the parameter to the objectdatasource of the control you are wanting to tie to.

Kind Regards,
Rob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Get SelectedValue of Control obrienkev C# 2005 3 November 8th, 2007 12:17 PM
Problems on using parameter fever168 JSP Basics 1 March 23rd, 2007 07:34 AM
Parameter Problems Odifius Access VBA 2 October 10th, 2006 03:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.