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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Empty row from Gridview

Status
Not open for further replies.

kalkumar

Programmer
Jul 7, 2006
40
US
Hi,

I have a Gridview and one button ADD which will insert new row to Gridview and is outside of Gridview. Gridview contain one button DELETE column which is used to delete that row from gridview.

When the Delete button is clicked I want to delete that row For this I am doing like this: Where ID is the unique column in Gridview.

private DataRow FindRowByID(string id)

{

DataTable dt = (DataTable)Session["dt"];

DataRow[] rows = dt.Select("ID = " + id.ToString());

return rows[0];

}

Gridview_RowCommand()

{

if (e.CommandName == "RemovePartner")

{

string ind = e.CommandArgument.ToString();

FindRowByID.Delete(ind);

}

}

This is working fine when the inserted row ha ID value. If the user add a new row but did not enter any value into ID column and clicked on Delete then ID contain null value then how to delete that newly inserted row from Gridview.

Thanks
 
In your database make the field required. Uncheck the allow null checkbox. Also you might want to make it a auto incrementing field, then you don't need to worry about the user filling in the id.

Ordinary Programmer
 
You could assign a temporary id (e.g. zero) when the new row is created. Add validation to make sure the user enters a different value and then if you ever need to find the row, you can use the id of zero if no other details have been entered.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top