repeater control
-
Hi.. I creatd some dynamic textboxes in repeater control.. Had a button to add textboxes.. and link button to delete the rows from db.. im deleting the rows from repeater based on id in the table...upto this its working fine. But when i click on add button to add more rows and if i want to delete those rows, as they dont have any id in table how do i delete those rows..
-
Hi.. I creatd some dynamic textboxes in repeater control.. Had a button to add textboxes.. and link button to delete the rows from db.. im deleting the rows from repeater based on id in the table...upto this its working fine. But when i click on add button to add more rows and if i want to delete those rows, as they dont have any id in table how do i delete those rows..
where you are keeping the newly added object?or in other words do u have any persisting DataSource object for repeater?
Arun Jacob http://codepronet.blogspot.com/
-
where you are keeping the newly added object?or in other words do u have any persisting DataSource object for repeater?
Arun Jacob http://codepronet.blogspot.com/
-
the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...
test-09 wrote:
the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...
when clicking new row button how you are adding rows to repeater?Do u have any persisting object in code behind?Have tried deleting by index of the repeater item?
Arun Jacob http://codepronet.blogspot.com/
-
test-09 wrote:
the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...
when clicking new row button how you are adding rows to repeater?Do u have any persisting object in code behind?Have tried deleting by index of the repeater item?
Arun Jacob http://codepronet.blogspot.com/
this is how im adding new row...
private void adddescription()
{
int rowIndex = 0;if (ViewState\["CurrentTable"\] != null) { //DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\]; dtDesc = (DataTable)ViewState\["CurrentTable"\]; DataRow drCurrentRow = dtDesc.NewRow(); if (dtDesc.Rows.Count > 0) { for (int i = 1; i <= dtDesc.Rows.Count; i++) { //extract the TextBox values TextBox box1 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextName"); TextBox box2 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDate"); TextBox box3 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDescript"); drCurrentRow = dtDesc.NewRow(); drCurrentRow\["RowNumber"\] = i ; ViewState\["RowNumber"\] = drCurrentRow\["RowNumber"\]; Label1.Text = ViewState\["RowNumber"\].ToString(); dtDesc.Rows\[i - 1\]\["DescriptionName"\] = box1.Text; dtDesc.Rows\[i - 1\]\["Date"\] = box2.Text; dtDesc.Rows\[i - 1\]\["Description"\] = box3.Text; rowIndex++; } dtDesc.Rows.Add(drCurrentRow); // ViewState\["CurrentTable"\] = dtDesc; } else { dtDesc = (DataTable)ViewState\["CurrentTable"\]; // dtDesc = (DataTable)ViewState\["CurrentTable"\]; DataRow descRow = dtDesc.NewRow(); // descRow\["ProjectID"\] = dtDesc.Rows.Count + 1; descRow\["DescriptionName"\] = ""; descRow\["Date"\] = ""; descRow\["Description"\] = ""; dtDesc.Rows.Add(descRow); // ViewState\["CurrentTable"\] = dtDesc; } } Bindrepeater(); }
-
this is how im adding new row...
private void adddescription()
{
int rowIndex = 0;if (ViewState\["CurrentTable"\] != null) { //DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\]; dtDesc = (DataTable)ViewState\["CurrentTable"\]; DataRow drCurrentRow = dtDesc.NewRow(); if (dtDesc.Rows.Count > 0) { for (int i = 1; i <= dtDesc.Rows.Count; i++) { //extract the TextBox values TextBox box1 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextName"); TextBox box2 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDate"); TextBox box3 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDescript"); drCurrentRow = dtDesc.NewRow(); drCurrentRow\["RowNumber"\] = i ; ViewState\["RowNumber"\] = drCurrentRow\["RowNumber"\]; Label1.Text = ViewState\["RowNumber"\].ToString(); dtDesc.Rows\[i - 1\]\["DescriptionName"\] = box1.Text; dtDesc.Rows\[i - 1\]\["Date"\] = box2.Text; dtDesc.Rows\[i - 1\]\["Description"\] = box3.Text; rowIndex++; } dtDesc.Rows.Add(drCurrentRow); // ViewState\["CurrentTable"\] = dtDesc; } else { dtDesc = (DataTable)ViewState\["CurrentTable"\]; // dtDesc = (DataTable)ViewState\["CurrentTable"\]; DataRow descRow = dtDesc.NewRow(); // descRow\["ProjectID"\] = dtDesc.Rows.Count + 1; descRow\["DescriptionName"\] = ""; descRow\["Date"\] = ""; descRow\["Description"\] = ""; dtDesc.Rows.Add(descRow); // ViewState\["CurrentTable"\] = dtDesc; } } Bindrepeater(); }
Okay.Delete button is in the repater.right?then in the delete button click event you'll get the item index and using that item index delete that object from the viewstate and rebind repeater.is that makes sense?
Arun Jacob http://codepronet.blogspot.com/
-
Okay.Delete button is in the repater.right?then in the delete button click event you'll get the item index and using that item index delete that object from the viewstate and rebind repeater.is that makes sense?
Arun Jacob http://codepronet.blogspot.com/
im losing the values in textboxs on postback.... i cant check which row im deleting correctly as the values go on postback...
int iddelete;
iddelete = ToInt(e.CommandArgument.ToString());
if (iddelete!=0)
{
//code....
}
else
{int count = e.Item.ItemIndex; // count = Convert.ToInt32(ViewState\["RowNumber"\]); //DataTable dtdelete = (DataTable)ViewState\["CurrentTable"\]; // count = dtdelete.Rows.Count - 1; dtdelete.Rows\[count\].Delete(); dtdelete.AcceptChanges(); Rptdescription.DataSource = dtdelete; Rptdescription.DataBind(); }
-
im losing the values in textboxs on postback.... i cant check which row im deleting correctly as the values go on postback...
int iddelete;
iddelete = ToInt(e.CommandArgument.ToString());
if (iddelete!=0)
{
//code....
}
else
{int count = e.Item.ItemIndex; // count = Convert.ToInt32(ViewState\["RowNumber"\]); //DataTable dtdelete = (DataTable)ViewState\["CurrentTable"\]; // count = dtdelete.Rows.Count - 1; dtdelete.Rows\[count\].Delete(); dtdelete.AcceptChanges(); Rptdescription.DataSource = dtdelete; Rptdescription.DataBind(); }
test-09 wrote:
im losing the values in textboxs on postback...
Which values you are loosing?ItemIndex is enough to delete it from ViewState?Is this code working?whats the difficulty you are facing in the above code? If you are saying about entered values in textboxes, then save that values to the persisting object before rebinding the repeater.
Arun Jacob http://codepronet.blogspot.com/
-
test-09 wrote:
im losing the values in textboxs on postback...
Which values you are loosing?ItemIndex is enough to delete it from ViewState?Is this code working?whats the difficulty you are facing in the above code? If you are saying about entered values in textboxes, then save that values to the persisting object before rebinding the repeater.
Arun Jacob http://codepronet.blogspot.com/
-
You might have 'hard coded' index of last row. Please check that. This could be the case. :laugh:
Thanks, Arindam D Tewary