|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView DataKeygrab a value from one of the fields in a gridView to populate a dropdown in another column of the gridview: I have a gridView that has 2 templated columns that contain drop-down lists. The first drop down list uses a value off of a formview on the same page for filtering. The 2nd drop-down is supposed to use the value off the first drop-down for it's parameter. I tried to add a parameter definition the same way I did referring to the FormView, but I get the following error: DataBinding: 'System.Web.UI.WebControls.GridView' does not contain a property with the name 'DataKey'. Offending Code: <asp:ObjectDataSource ID="dsTarget" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetTargetsForSite" TypeName="AL.clsSite"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="SiteID" PropertyName="DataKey("SiteID")" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> wheras this code works: <asp:ObjectDataSource ID="dsSite" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetSitesForPublisher" TypeName="AL.clsSite"> <SelectParameters> <asp:ControlParameter ControlID="FormView1" Name="PublisherID" PropertyName="DataKey("PublisherID")" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> So, first, is this the best way to get a value out of a formView ? 2nd, how do I get a value from the GridView ? Thanks, Mark Richards Hi Mark,
As the message indicated, there is no property on the GridView named "DataKey" whereas there is a "DataKey" property on the FormView. The GridView has a collection for the DataKeys http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx On the GridView you may use the SelectedDataKey.Values[i] (where i is the index of the key) as I did in this demo: http://www.webswapp.com/CodeSamples/aspnet20/GridView_1c.aspx Show quote "Mark Richards" wrote: > I posted this earlier, and got no response. Basically I need to be able to > grab a value from one of the fields in a gridView to populate a dropdown in > another column of the gridview: > > > I have a gridView that has 2 templated columns that contain drop-down lists. > The first drop down list uses a value off of a formview on the same page for > filtering. The 2nd drop-down is supposed to use the value off the first > drop-down for it's parameter. I tried to add a parameter definition the > same way I did referring to the FormView, but I get the following error: > > DataBinding: 'System.Web.UI.WebControls.GridView' does not contain a > property with the name 'DataKey'. > > Offending Code: > <asp:ObjectDataSource ID="dsTarget" runat="server" > OldValuesParameterFormatString="original_{0}" > SelectMethod="GetTargetsForSite" TypeName="AL.clsSite"> > <SelectParameters> > <asp:ControlParameter ControlID="GridView1" Name="SiteID" > PropertyName="DataKey("SiteID")" Type="Int32" /> > </SelectParameters> > </asp:ObjectDataSource> > > > > wheras this code works: > > <asp:ObjectDataSource ID="dsSite" runat="server" > OldValuesParameterFormatString="original_{0}" > SelectMethod="GetSitesForPublisher" TypeName="AL.clsSite"> > <SelectParameters> > <asp:ControlParameter ControlID="FormView1" Name="PublisherID" > PropertyName="DataKey("PublisherID")" Type="Int32" /> > </SelectParameters> > </asp:ObjectDataSource> > > > > > > So, first, is this the best way to get a value out of a formView ? 2nd, how > do I get a value from the GridView ? > > > > Thanks, > > Mark Richards > > > |
|||||||||||||||||||||||