user186585
user186585

Reputation: 512

FormView change data before inserting to sql?

I'm using FormView to add new data to the sql server. I try to change some of the data that the user inserting, like replace "a" with "A"

I try to use the following code:

protected void FormViewInsertEventHandler(object sender, SqlDataSourceCommandEventArgs e)
{
    e.Values["Institution_fax"] = "33333";
}

and

<asp:SqlDataSource ID="SqlDataSourceSP" runat="server" 
  ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" 
  InsertCommand="usp_limodimInstitution_insert" 
  InsertCommandType="StoredProcedure" 
  SelectCommand="select * from tbl_limodim_Institution">

But i get the following error

No overload for 'FormViewInsertEventHandler' matches delegate 'System.Web.UI.WebControls.FormViewInsertEventHandler'

What have I missed?

Upvotes: 0

Views: 551

Answers (3)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

You can try to change signature of your delegate to

public delegate void FormViewInsertEventHandler( Object sender, FormViewInsertEventArgs e )
{
   ......
}

Upvotes: 0

SwDevMan81
SwDevMan81

Reputation: 49988

Your argument to the event handler is incorrect

protected void FormViewInsertEventHandler(object sender, SqlDataSourceCommandEventArgs e)

should be:

protected void FormViewInsertEventHandler(object sender, FormViewInsertEventArgs e)

Upvotes: 1

HasaniH
HasaniH

Reputation: 8402

Your method signature is incorrect for the event handler, it should be:

protected void FormViewInsertEventHandler(object sender, FormViewInsertEventArgs e)
{
    e.Values["Institution_fax"] = "33333";
}

You can't replace the FormViewInsertEventArgs with SqlDataSourceCommandEventArgs.

Upvotes: 1

Related Questions