Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert new row in a datagrid as the first row

Status
Not open for further replies.

WorkSuxs

Programmer
Jan 26, 2005
28
US
Hi, I'm new to asp.net(VB).

I have a datagrid that is displayed in a table. The user enters information (first name, last name, phone number, division, sales city) into textboxes and clicks a button to add it to the datagrid. I would like to have the new information to be in the first row. I tried the dataTableName.Rows.InsertAt(datarowinfo, 0) and this does not work. Any ideas?
 
Here is what I do

For my OnItemCreated function of my DataGrid

Code:
    protected void dgItems_ItemCreated(Object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex == 0)
        {
            LinkButton lb = (LinkButton)e.Item.Cells[0].Controls[0];

            if (lb.Text == "Edit")
            {
                lb.Text = "Insert New Record";
            }


        }
}

My databinding function
Code:
    protected void BindDataGrid()
    {
        DataSet ds = GetAllSiteOptions(Convert.ToInt32(ddlSite.SelectedValue));
        System.Data.DataRow BlankRow = ds.Tables[0].NewRow();
        ds.Tables[0].Rows.InsertAt(BlankRow, 0);
        dgItems.DataSource = ds;
        dgItems.DataBind();


    }

HTH
 
also look at this thread.... thread855-1238747

we were talking about this awhile back..

 
Thanks both of you. I'll look at the thread and the code provided.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top