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