Pippo J Pluto
Pippo J Pluto

Reputation: 1

Data in GridView from query

I have a query that return two rows ("Name", "Surname", "Age": these are headers of my query).
I want to see a table in myPage.aspx with "Name"'s column and add a new column (this new column has two buttons thats execute other queries).
Here there is my code (VB code of my aspx page):

Private Sub Validazione_Load(sender As Object, e As EventArgs) Handles Me.Load
    id_persona = '001'
    'Execute query
    Dim dbCmd As SqlCommand
    Dim dbRdr As SqlDataReader
    Dim dtDataTable As New DataTable
    dbCmd = fpd.dbConn.CreateCommand
    With dbCmd
        .CommandType = CommandType.StoredProcedure
        .CommandText = "sp_fo_myStoreProcedure"
        .Parameters.Add("@id_PERSONA", SqlDbType.Int).Value = ContextHandler.id_PERSONA
    End With
    dbRdr = dbCmd.ExecuteReader
    'Load data from query (two rows)
    dtDataTable.Load(dbRdr)        
    myGridView.DataSource = dtDataTable
    myGridView.DataBind()
    dbRdr.Close()
    dbCmd.Dispose()
End Sub

I am sure that I have two rows.

My problem: the myGridView is "double", two tables side by side. This is my aspx page:

<asp:GridView ID="myGridView" runat="server">
<Columns>
        <asp:CommandField />             
        <asp:BoundField DataField="namePers" HeaderText="Name Person" />
<asp:TemplateField HeaderText="Azioni">
        <ItemTemplate>
           <asp:LinkButton ID="btnPippo" style="padding-left: 5px; margin-top: 2px; padding-right: 5px; width: 108px; text-align: center;"  runat="server" CssClass="btnlink" CommandArgument='Pippo'>
                FirstBtn
           </asp:LinkButton>
           <asp:LinkButton ID="btnPluto" style="padding-left: 5px; margin-top: 2px; padding-right: 5px; width: 108px; text-align: center;"  runat="server" CssClass="btnlink" CommandArgument='Pluto'>
                SecondBtn
             </asp:LinkButton>
        </ItemTemplate>
</asp:TemplateField>

So, I want:
1) Why I see two tables? Where is my error?
2) see only "Name" columns with its data
3) Add a new column (I think there isn't problems)

Upvotes: 0

Views: 30

Answers (1)

Siva Rm K
Siva Rm K

Reputation: 294

you have to set autoGeneratecolumn = "false"

<asp:GridView ID="myGridView" runat="server" autogeneratecolumns="False">

Upvotes: 1

Related Questions