gridview appears only after forced postback - why?

  • Thread starter Thread starter COHENMARVIN
  • Start date Start date
C

COHENMARVIN

I have a sqldatasource control that uses 3 parameters. I have a
gridview that depends on the sqldatasource control The 3 parameters
are session variables. So in my code, I set the values of those 3
session variables, and then do a 'gridview.databind' and hope that
something happens.
But nothing happens - the gridview does not appear.
Then I noticed that if I click on a dropdownlist that has
'autopostback' enabled, that the page refreshes and suddenly my grid
is visible and filled with data.

Is there any way to force this post back without clicking on a
dropdownlist?

I tried making the gridview visible and invisible by settting its
'visible' property, and that did not work. I tried putting it in a
panel and setting that to visible and invisible, but that did not
work.

I did get advice to force execution of the select statement in the sql
data source control, but how does one do that?

Thanks for any help.
-- Marvin
 
Try setting a breakpoint right before you set those parameters and call the
grid's DataBind method and make sure that the code is running on the 1st
time you load the page, if it's running then set a watch or use the
immediate window to verify that you're actually setting the parameters to
the right values.

If you can't figure it out after than then post your code. Including the
ASPX.

Hope that helps,
Fernando L Rodriguez, MCP
 
Try setting a breakpoint right before you set those parameters and call the
grid's DataBind method and make sure that the code is running on the 1st
time you load the page, if it's running then set a watch or use the
immediate window to verify that you're actually setting the parameters to
the right values.

If you can't figure it out after than then post your code. Including the
ASPX.
I tried the breakpoint, and the code is getting executed, but nothing
it does shows up on the screen. even setting the label
'lbldebug.text' does not show up on the screen, though its value does
get set according to the debug window.

Here is the code - it is in a usercontrol.
Protected Sub btnGetData_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnGetData.Click
LoadGridView()
End Sub
Protected Sub LoadGridView()
Dim SQL As String = ""
Dim Dt As New Data.DataTable
Dim StartDate As Date = #1/1/1900#
Dim EndDate As Date = #1/1/1900#
Dim ReportName As String = ""


If IsDate(Me.txtStartDate.Text) Then
StartDate = Convert.ToDateTime(Me.txtStartDate.Text)
Else
Me.lblMessage.Text = "Enter a Start Date to Continue"
Exit Sub
End If

If IsDate(Me.txtEndDate.Text) Then
EndDate = Convert.ToDateTime(Me.txtEndDate.Text)
Else
Me.lblMessage.Text = "Enter an End Date to Continue"
Exit Sub
End If

If StartDate > EndDate Then
Me.lblMessage.Text = "Start Date Cannot Be GREATER than
End Date"
Exit Sub
End If
Dim strReportName As String

strReportName = Me.ddlReports.SelectedValue
If strReportName = "Select a Report" Then
Me.lblMessage.Text = "Select a Report to Continue!"
Exit Sub
End If

ReportName = GetsProcForReport()

lblDebug.Text = "strReportName is " & strReportName.ToUpper
If strReportName.ToUpper.Trim = "DAILY OUTREACH" Then
Delete3OutreachTablesUnusedRecords()

Session("DOStartDate") = Me.txtStartDate.Text
Session("DOEndDate") = Me.txtEndDate.Text
Session("DOAgencyName") =
Me.DropDownListAgencies.SelectedItem.Text
Me.SqlDataSourceDailyOutreachReport.DataBind()
Me.GridViewDailyOutreachReport2.DataBind()
Me.lblDebug.Text = Session("DOStartDate") & ", " &
Session("DOEndDate") & ", " & Session("DOAgencyName")

And here is the ascx code:
<asp:Label ID="lblDebug" runat="server" ForeColor="Lime"
Width="431px"></asp:Label>
<table>
<tr>
<td style="width: 3px">
<asp:Label ID="lblStartDate" runat="server"
Text="Start Date" Width="80px" ForeColor="Black"></asp:Label></td>
<td style="width: 3px">
<asp:TextBox ID="txtStartDate" runat="server"
Width="90px" BorderStyle="Groove"></asp:TextBox></td>
<td style="width: 3px">
<asp:ImageButton ID="imgStartDate" runat="server"
ImageUrl="~/images/Calendar_scheduleHS.bmp"
ValidationGroup="txtStartDate" /></td>
<td style="width: 3px">
<asp:Label ID="lblPholder1" runat="server"
ForeColor="White" Text="__"></asp:Label></td>
<td style="width: 3px">
<asp:Label ID="lblEndDate" runat="server"
ForeColor="Black" Text="End Date" Width="80px"></asp:Label></td>
<td style="width: 3px">
<asp:TextBox ID="txtEndDate" runat="server"
BorderStyle="Groove" Width="90px"></asp:TextBox></td>
<td style="width: 3px"><asp:ImageButton ID="imgEndDate"
runat="server" ImageUrl="~/images/Calendar_scheduleHS.bmp"
ValidationGroup="txtEndDate" /></td>
<td style="width: 3px">
</td>
</tr>
<tr>
<td style="width: 3px">
<asp:Label ID="Label1" runat="server"
ForeColor="White" Text="-" Width="80px"></asp:Label></td>
<td style="width: 3px">
</td>
<td style="width: 3px">
</td>
<td style="width: 3px">
</td>
<td style="width: 3px">
</td>
<td style="width: 3px">
</td>
<td style="width: 3px">
</td>
<td style="width: 3px">
</td>

</tr>
<tr>
<td colspan="2">
<asp:DropDownList ID="ddlReports" runat="server"
Width="181px" AutoPostBack="True">
</asp:DropDownList></td>
<td colspan="3">
<asp:Button ID="btnGetData" runat="server"
OnClick="btnGetData_Click" Text="Generate Report" Width="123px" /></
td>
<td colspan="3">
<asp:Button ID="btnExport" runat="server"
OnClick="btnExport_Click" Text="Export To Excel" Width="116px" /></td>
</tr>


<tr><td colspan="8" align="center">
<asp:Label ID="LblAgencies" runat="server"
Text="Agencies" ForeColor="Black" Visible="False"></asp:Label>


<asp:DropDownList ID="DropDownListAgencies" runat="server"
Visible="False">
</asp:DropDownList><br />
&nbsp;</td></tr>

<tr>
<td colspan="8">
<asp:Label ID="Label2" runat="server"
ForeColor="White" Text="__"></asp:Label></td>
</tr>
<tr>
<td colspan="8">
</td>
</tr>
</table>
asdfsdafasdfasd<asp:SqlDataSource
ID="SqlDataSourceDailyOutreachReport" runat="server"
ConnectionString="<%$
ConnectionStrings:DBDHSCentralConnectionString %>"
SelectCommand="DailyOutreachReport"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="StartDate"
SessionField="DOStartDate" Type="DateTime" />
<asp:SessionParameter Name="endDate"
SessionField="DOEndDate" Type="DateTime" />
<asp:SessionParameter Name="AgencyName"
SessionField="DOAgencyName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

&nbsp;&nbsp;
<asp:GridView ID="GridViewDailyOutreachReport2" runat="server"
AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSourceDailyOutreachReport">
<asp:BoundField DataField="ID" HeaderText="ID"
InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Date Reported" HeaderText="Date
Reported" SortExpression="Date Reported" />
<asp:BoundField DataField="Date Submitted" HeaderText="Date
Submitted" SortExpression="Date Submitted" />
<asp:BoundField DataField="Agency Name" HeaderText="Agency
Name" SortExpression="Agency Name" />
</Columns>
</asp:GridView>
<br />
THANKS
 
I should mention that the page has ajax controls. My solution finally
was to do a response.redirect to another page where I put the grids.
They work there.
 
Back
Top