Control Button to Datagridview
<p>I'm a new member here. I want to ask something. Best regards for everyone of you to answer my questions. Sorry for my bad English. I'm from Indonesia.
I have two radiobutton, two textbox, two datagridview and one button. The scenario is my first textbox is Input by InvoiceNumber and the second Textbox input by AccountNumber. My question is when I input by Invoicenumber and I click Button Search the datagridview for Invoicenumber will show and when I input by Accountnumber the datagridview for Accounrnumber will show. This is my Code:</p>

<p>Default.aspx.vb: (Updated below to display code correctly by Piyush Khatri)</p>

<pre><code>Protected Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click
    periode = cbbulan.SelectedValue.ToString + Microsoft.VisualBasic.Right(cbtahun.Text, 2).ToString
    If txtseacrh.Text Then
        Me.BindGrid(txtseacrh.Text, periode)
        tampildata()
        Label3.Text = "Consignee : "
        Label4.Text = "Address : "
        Label5.Text = "Product :"
    End If
    Me.BindGrid2(txtsearch2.Text)
End Sub

Private Sub BindGrid(RefNo As String, periode As String)
    Dim constr As String = ConfigurationManager.ConnectionStrings("dbCon").ConnectionString
    Using con As New SqlConnection(constr)
        Using cmd As New SqlCommand()

            cmd.CommandText = "Declare @awb As varchar(50)
                               Select  @awb=awb from msdetail md inner join msdata mt On mt.PuNo=md.Puno 
                               where md.Puno='" &amp; RefNo &amp; "' 
                               Select '1' as no, Convert(varchar(12), pudate, 103) As Date,CONVERT(varchar(8), pudate,8) as time,'PU' AS status,'' as Recipient, '' as Remaks,'' as PIC from MsDetail where AWB=@awb 
                               And Periode='" &amp; periode &amp; "'
                               union 
                               Select '2' as no, CONVERT(varchar(12),pudatein,103) as date,CONVERT(varchar(8), pudatein,8) as time,'DE' AS status,'' as Recipient, '' as Remaks, IdUser as PIC from MsDetail where AWB=@awb 
                               And Periode='" &amp; periode &amp; "' 
                               UNION 
                               Select '3' as no, CONVERT(varchar(12),stdate,103) as date,CONVERT(varchar(8), stdate,8) as time,StStt AS status,StPenerima as Recipient,StRel as Remaks, st.IdUser as PIC from status st 
                               inner Join MsDetail md on md.AWB=st.AWB where md.AWB=@awb And Periode='" &amp; periode &amp; "' order by no"
            cmd.Connection = con

            Dim dt As New DataTable()
            Using sda As New SqlDataAdapter(cmd)
                sda.Fill(dt)
                GridView1.DataSource = dt
                GridView1.DataBind()
            End Using
        End Using
    End Using
End Sub

Private Sub BindGrid2(Puno As String)
    Dim constr As String = ConfigurationManager.ConnectionStrings("dbCon").ConnectionString
    Using con As New SqlConnection(constr)
        Using cmd As New SqlCommand()

            cmd.CommandText = "select Refno,Field1,(CONVERT (varchar(10),PuDate,103)) as PuDate,(Convert (varchar(10),Pudatein,103))as Pudatein,mdcompany,MdAdd1,mdadd2,mdadd3,mdadd4,StStt,(CONVERT (varchar(10),StDate,103)) as StDate,StPenerima,StRel from MsDetail inner join MsData on MsDetail.PuNo=MsData.PuNo
                               left join Status on MsDetail.AWB=Status.AWB where MsData.Refno='" &amp; Puno &amp; "'"
            cmd.Connection = con

            Dim dt As New DataTable()
            Using sda As New SqlDataAdapter(cmd)
                sda.Fill(dt)
                GridView2.DataSource = dt
                GridView2.DataBind()
            End Using
        End Using
    End Using
End Sub

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        'Fill Years
        For i As Integer = Year(Now) - 1 To Year(Now)
            cbtahun.Items.Add(i.ToString())
        Next
        cbtahun.Items.FindByValue(System.DateTime.Now.Year.ToString()).Selected = True 'set current year as selected

    End If
End Sub

Protected Sub cbbulan_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbbulan.SelectedIndexChanged
    'Session["cbbulan"]=DropDownList.SelectedValue;
End Sub
Private Sub koneksi()
    strconn = WebConfigurationManager.ConnectionStrings("dbCon").ConnectionString
    MyCn = New SqlConnection(strconn)
    If MyCn.State &lt;&gt; Data.ConnectionState.Closed Then MyCn.Close()
    MyCn.Open()
End Sub
Private Sub tampildata()
    koneksi()
    Dim sql As String
    Dim cmd As SqlCommand
    Dim dread As SqlDataReader

    ' Dim constr As String = ConfigurationManager.ConnectionStrings("a").ConnectionString

    sql = "select prname,MdName,isnull(MdAdd1,'') + ' ' + isnull(MdAdd2,'') + ' ' + isnull(MdAdd3,'') as ALAMAT from MsData inner join MsDetail on MsDetail.PuNo=MsData.PuNo 
           Left Join Produk on MsDetail.Code=Produk.Code where msdata.PuNo='" &amp; txtseacrh.Text &amp; "'"
            cmd = New SqlCommand(Sql, MyCn)
            dread = cmd.ExecuteReader
            If dread.HasRows Then
                While dread.Read = True
                    Label1.Text = dread.Item("mdName").ToString
                    Label2.Text = dread.Item("ALAMAT").ToString
                    Label6.Text = dread.Item("PrName").ToString
                End While
                dread.Close()
            End If
End Sub
</code></pre>