Hi
I have a gridview which should populate based on some criteria that the end user selects.
To enable the user to enter the required criteria i have added some Web Controls like Textbox,Drop Down Lists etc.

My code behind for getting the data is as below
Here the value from each Textbox or Drop Down List is assigned to the SQL Parameter. which is passed on to the Stored Procedure "GetData"
My issue is that when the page loads i want all the records to be displayed.
However this is not the case. The records get populated in the Gridview only if i click on a Button.
Could anyone advise me how the same could happen at the Page_Load stage, or what could be causing the issue.
I have a gridview which should populate based on some criteria that the end user selects.
To enable the user to enter the required criteria i have added some Web Controls like Textbox,Drop Down Lists etc.

My code behind for getting the data is as below
Code:
Imports System.Data
Imports System.Data.SqlClient
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myconnection As SqlConnection
Dim mydataadapter As SqlDataAdapter
Dim DS As DataSet
If txtSearchRequest.Text = "" Then
txtSearchRequest.Text = "%"
End If
myconnection = New SqlConnection("server=TestServer;database=TestDatabase;Trusted_Connection=yes")
mydataadapter = New SqlDataAdapter("GetData", myconnection)
mydataadapter.SelectCommand.CommandType = CommandType.StoredProcedure
'Adding the parameters and assigning the values
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_request", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_request").Value = txtSearchRequest.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_process_status", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_process_status").Value = ddlProcessStatus.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_mitigated_status", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_mitigated_status").Value = ddlMitigatedStatus.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_age_slab", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_age_slab").Value = ddlAgeSlab.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_nssr", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_nssr").Value = ddlStandardNSSR.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_owner", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_owner").Value = ddlOwner.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_reassigned_to", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_reassigned_to").Value = ddlReassignedTo.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@ui_tool", SqlDbType.NVarChar, 4000))
mydataadapter.SelectCommand.Parameters("@ui_tool").Value = ddlTool.Text
mydataadapter.SelectCommand.Parameters.Add(New SqlParameter("@row_count", SqlDbType.Int))
mydataadapter.SelectCommand.Parameters("@row_count").Direction = ParameterDirection.Output
DS = New DataSet()
mydataadapter.Fill(DS, "mydata")
lblGetCount.Text = DS.Tables(0).Rows.Count().ToString()
lblGetCount.Text = mydataadapter.SelectCommand.Parameters("@row_count").Value & " Records Found!"
gridview1.DataSource() = DS.Tables("mydata").DefaultView
gridview1.DataBind()
mydataadapter.Dispose()
myconnection.Close()
End Sub
Here the value from each Textbox or Drop Down List is assigned to the SQL Parameter. which is passed on to the Stored Procedure "GetData"
My issue is that when the page loads i want all the records to be displayed.
However this is not the case. The records get populated in the Gridview only if i click on a Button.
Could anyone advise me how the same could happen at the Page_Load stage, or what could be causing the issue.
Comment