Jeremiah
Jeremiah

Reputation: 5

C# and ASP.net Getting a specific column from a dataset in gridview

How do I go about getting just one specific column from a dataset?

I want to get the column where the user name equals the current logged in user, which I know how to do and is sort of working.

Here is the code I am using to bind the dataset to the gridview

dsUser myDataSet3 = new dsUser();

myDataSet3 = Users.GetNote(Server.MapPath("wsc_database.accdb"), UserID);

grdNote.DataSource = myDataSet3.Tables["User"].Rows[0]["usr_note"];

grdNote.DataBind();

Which sort of gives me the right result, however, the formatting is ridiculous (evidently can't post the picture)

but it gives me the column I want but formats badly like so.

[t]
[h]
[i]
[s]

Each letter is separated in it's own row and column.

How can I get the same column result but not split up like this?

I am new at this and hope that I am being clear, been struggling with this all day. A thanks in advance to anyone who can help!

Upvotes: 0

Views: 1486

Answers (1)

fenix2222
fenix2222

Reputation: 4730

grdNote.DataSource = myDataSet3.Tables["User"].DefaultView;
grdNote.DataBind(); 

Then in html bind your column to "usr_note" column

<asp:GridView ID="grdNote" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="usr_note" HeaderText="Note" />
    </Columns>
</asp:GridView>

My question is why are you trying to diplay 1 record in grid view, what is the point of using gridview if it is only one record?

Upvotes: 1

Related Questions