• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

How do I pass the SelectedValue of a RadioButtonList to a UpdateParameter in a SqlDataSource from a GridView Control?

How do I pass the SelectedValue of a RadioButtonList to a UpdateParameter in a SqlDataSource from a GridView Control?

this is what I have...
protected void uxChecksGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        RadioButtonList r = (RadioButtonList)uxChecksGridView.Rows[e.RowIndex].FindControl("uxAddAddressRadioButtonList");
        uxChecksSqlDataSource.UpdateParameters["HasAddress"].DefaultValue = r.SelectedValue;
    }
 
    <asp:SqlDataSource ID="uxChecksSqlDataSource" runat="server"
                       ConnectionString="<%$ ConnectionStrings:infonet %>"
                       SelectCommandType="StoredProcedure"
                       SelectCommand="sp_GetDisbursementOfFundsChecksInformation"
                       DeleteCommandType="StoredProcedure"
                       DeleteCommand="sp_DeleteDisbursementOfFundsChecks"
                       InsertCommandType="StoredProcedure"
                       InsertCommand="sp_InsertDisbursementOfFundsChecks"
                       UpdateCommandType="StoredProcedure"
                       UpdateCommand="sp_UpdateDisbursementOfFundsChecks">
        <SelectParameters>
            <asp:SessionParameter Name="DID" SessionField="DID" />
        </SelectParameters>  
        <DeleteParameters>
            <asp:SessionParameter Name="DID" SessionField="DID" />
            <asp:Parameter Name="ID" Type="Int32" />        
        </DeleteParameters>   
        <InsertParameters>
            <asp:Parameter Type="Int32" Name="DID" />
            <asp:Parameter Type="Boolean" Name="CashiersCheck" />          
            <asp:Parameter Type="String" Name="PayableTo" />
            <asp:Parameter Type="Double" Name="Amount" />
            <asp:Parameter Type="String" Name="Purpose" />  
            <asp:Parameter Type="Boolean" Name="HasAddress" />              
            <asp:Parameter Type="String" Name="Address" />
            <asp:Parameter Type="String" Name="City" />
            <asp:Parameter Type="Int32" Name="State" />
            <asp:Parameter Type="String" Name="Zip" />                             
         </InsertParameters> 
         <UpdateParameters>
            <asp:Parameter Name="CashiersCheck" />
            <asp:Parameter Name="PayableTo" />     
            <asp:Parameter Name="Amount" />    
            <asp:Parameter Name="Purpose" />              
            <asp:Parameter Type="String" Name="Address" />
            <asp:Parameter Type="String" Name="City" />
            <asp:Parameter Type="Int32" Name="State" />
            <asp:Parameter Type="String" Name="Zip" />  
            <asp:Parameter Type="Boolean" Name="HasAddress" />
            <asp:SessionParameter Name="DID" SessionField="DID" />
            <asp:Parameter Name="ID" Type="Int32" />                  
         </UpdateParameters>               
    </asp:SqlDataSource>

Open in new window

0
mmedi005
Asked:
mmedi005
  • 2
  • 2
1 Solution
 
jabcocoCommented:
Handle the "OnUpdating" on your sql datasource and set the parameter you need.
.... OnUpdating="uxChecksSqlDataSource_Updating"></asp:SqlDataSource>
 
    protected void uxChecksSqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        //Get your radiobuttonlist instance
 
        e.Command.Parameters["CashiersCheck"].Value = r.SelectedValue;
    }

Open in new window

0
 
mmedi005Author Commented:
ok, tried with just manual putting in the value myself...wanted to test without getting the radiobuttonlist.selectedvalue first....

i got this error:

An SqlParameter with ParameterName 'HasAddress' is not contained by this SqlParameterCollection.
    protected void uxChecksSqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        e.Command.Parameters["HasAddress"].Value = "True";
    }

Open in new window

0
 
jabcocoCommented:
try
e.Command.Parameters["@HasAddress"].Value = "True";

Open in new window

0
 
mmedi005Author Commented:
that works, but how do i find the radiobuttonlist from the row im making the update in from the GridView Control?
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now