0

I have this command field in DetailsView.

<asp:CommandField ShowInsertButton="True" CancelText="Reset" />

When user click this link, it inserts the user filled data in DetailsView into database. But I want to set text to two text boxes in this DetailsView before inserting. I can do it in code behind. I have tried this by adding OnItemInserting event to DetailsView. But it's not working. Data set in code behind not inserted to database.

code behind

protected void ABC_DV_ItemInserting(Object sender, DetailsViewInsertEventArgs e)
        {

  TextBox p = (TextBox)LKArea_DV.FindControl("txt_p");

  TextBox x= (TextBox)ABC_DV.FindControl("txt_x");
  TextBox y= (TextBox)ABC_DV.FindControl("txt_y");

  string[] q = p.Text.Trim().Split(',');

  x.Text = q[0];
  y.Text = q[1];

       }

How could I do this?

4

1 Answer 1

0

Use ItemCommand Event

  1. Get Controls like Textbox from your DetailView control.
  2. Check if they are NULL
  3. If not null then grab the values
  4. Perform Insert , update any operation you like
  5. Commit the changes
  6. Rebind your control

It should work. hope that helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.