How can I debug the parameters passed when using a

2019-07-21 08:16发布

问题:

Say I have some sort of datagrid or repeater on a .aspx page, and my data source is defined inline like:

<asp:SqlDataSource ID="ds1" runat="server" ConnectionString="..."
SelectCommand="some_proc" ...>
  <SelectParameters>
             <asp:ControlParameter ControlID="ddlYear" Name="Year" .. />
   </SelectParameters>
</asp:SqlDataSource>

How can I debug my code so I can see exactly what the value of Year is when it binds to the grid?

回答1:

You can hook into the SqlDataSource events:

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
    foreach (DbParameter P in e.Command.Parameters)
    {
        Response.Write(P.ParameterName + "<br />");
        Response.Write(P.DbType.ToString() + "<br />");
        Response.Write(P.Value.ToString() + "<br />");
    }
}

Of course, you may want to send the output to the debug window.