steve
steve

Reputation: 123

How to display a single row in asp.net web forms?

I ask myself how I can display a single row from a datatable object in a control like a gridview.

I already did it with label objects like here: (this is in load event. I already have buttons which increment the zero and decrement)

 Tbname.Text = (dset.Tables("coduta").Rows(0).Item("Firma"))
        TbStraße.Text = (dset.Tables("coduta").Rows(0).Item("Straße_Firma"))
        TbHausnummer.Text = (dset.Tables("coduta").Rows(0).Item("Hausnummer_Firma"))
        TbOrt.Text = (dset.Tables("coduta").Rows(0).Item("Ort_Firma"))

the point is I want to show the specific row in something like a gridview control. The only Idea i have is, to create a new table out of the row and that looks like a too complicated way for this. I hope guys can help

cheers steven

Upvotes: 0

Views: 1674

Answers (2)

Jahangeer
Jahangeer

Reputation: 478

try

da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();

da.SelectCommand = new SqlCommand(@"SELECT * FROM coduta", connString);
da.Fill(ds, "coduta");
dt = ds.Tables["coduta"];

foreach (DataRow dr in dt.Rows)
{
    //here is your row of data
}

Upvotes: 0

Imad
Imad

Reputation: 7490

I am from C# background but this approach should help you.

  1. Get first row from existing table.
  2. Make clone of existing table.
  3. Add that row to clone table.
  4. Assign that table as datasource for grid

    DataRow dr = dset.Tables("coduta").Rows(0); 
    DataTable dtNew = dset.Tables("coduta").Clone();
    dtNew.Rows.Add(dr.ItemArray);
    grid.DataSource = dtNew;
    grid.DataBind();
    

Upvotes: 1

Related Questions