Wednesday, March 23, 2016

How do I refactor an ObjectDataSource to hand in a variable to a method in lieu of just calling a method without any parameters at the signature?

There probably is a way but I can't tell you what it is, I just hacked around the problem. I deleted this from my web form...

<asp:ObjectDataSource ID="MySource" runat="server"
      OldValuesParameterFormatString="original_{0}" SelectMethod="DoSomething"
      TypeName="Whatever.MyClassElsewhere"></asp:ObjectDataSource>

 
 

...and put this in my code behind.

List<Stuff> stuff = MyClassElsewhere.DoSomething(13);
var gridViewDataComboBoxColumn =
      (GridViewDataComboBoxColumn)MyGrid.Columns["Meh"];
gridViewDataComboBoxColumn.PropertiesComboBox.DataSource = stuff;

 
 

What I am trying to do is hydrate the selectable values at a GridViewDataComboBoxColumn which is a column header in an ASPxGridView (MyGrid in my example above) so I will need to doctor up the following markup to remove the DataSourceID parameter.

<dx:GridViewDataComboBoxColumn FieldName="Meh" Caption="Yawn">
   <PropertiesComboBox DataSourceID="MySource" ValueField="StuffyValue"
         TextField="StuffyName" ValueType="System.String"
         DropDownStyle="DropDown" />
</dx:GridViewDataComboBoxColumn>

 
 

Addendum 3/27/2016: It has been pointed out to me over Twitter that this has this example:

<asp:objectdatasource
   id="ObjectDataSource1"
   runat="server"
   selectmethod="GetEmployee"
   typename="Samples.AspNet.CS.EmployeeLogic">
   <selectparameters>
      <asp:querystringparameter name="EmployeeID" querystringfield="empid"
            defaultvalue="-1" />
   </selectparameters>
</asp:objectdatasource>

No comments:

Post a Comment