Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL .NET Gridview question

  • 10-09-2006 4:02pm
    #1
    Closed Accounts Posts: 2,585 ✭✭✭


    Hi Everyone,

    I'm new to MYSQl and .NET so hopefully comeone can help me with this. I cann't figure out how to change the column names. I have a Gridview which I am populating from a MySQL database as follows:
    // Set up connection
    MySqlConnection conn = new MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=password");

    // Data Adaptor
    MySqlDataAdapter da;

    da = new MySqlDataAdapter("SELECT name, address, phone_number from details", conn);
    DataSet ds = new DataSet();
    da.Fill( ds, "Details" );
    grd.DataSource = ds;
    grd.DataBind();

    How can I change the column names in the grid?

    Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    You can change them in either the HTML for the gridview or by right-clicking on the gridview and choosing Show Smart Tag -> Edit Columns... Select each column in the Selected fields list and set its HeaderText property.

    Google GridView Tutorial and have a look at what comes up, http://www.4guysfromrolla.com/ are always good.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    http://www.gridviewguy.com/ is another good one. Not as comprehensive as 4guysfromrolla, but some nice little tips and tricks.


  • Registered Users, Registered Users 2 Posts: 1,464 ✭✭✭evilhomer


    You could also do it on the SQL side

    SELECT name as 'first name', address as 'customer address', phone_number as 'Phone No.' from details

    it's pretty easy on that side and keeps the VB code to a minimum.


  • Closed Accounts Posts: 2,585 ✭✭✭HelterSkelter


    Thanks for the help guys. Will give those suggestions a go.


Advertisement