Tips & Tricks for ASP.NET - C#

Google site Search
Formview with Dropdownlist Insert Update

INSERT


Dropdownlist in the insert item template of Form view
--------------------------------------------------------


<asp:DropDownList ID="ddStakeHolderType" runat="server">
 <asp:ListItem Value="1">Consultation</asp:ListItem>
        <asp:ListItem Value="2">Planning Permission</asp:ListItem>
</asp:DropDownList>


call function in the inserting of sqldatasource
-----------------------------------------------

    <asp:SqlDataSource ID="sqlDSStakeholders" runat="server"  OnInserting="sqlDSStakeholders_inserting"
OnUpdating="sqlDSStakeholders_updating"

Parameter in the Query
-------------------------


InsertCommand="INSERT INTO [DMS_Stakeholders_T] ([stakeholdertype],[Name], [abbreviation], [address]) VALUES (@stakeholdertype, .......

UpdateCommand="UPDATE [DMS_Stakeholders_T] SET [stakeholdertype]=@stakeholdertype, [N ........


Parameter in the datasource - should be there in insert and update parameters
-----------------------------------------------------------------------------


<asp:Parameter Name="stakeholdertype" Type="String" />


function in the code behind
--------------------------------

 protected void sqlDSStakeholders_inserting(object sender, SqlDataSourceCommandEventArgs  e) {

        DropDownList ddStType = (DropDownList)FormView1.FindControl("ddStakeHolderType");
        e.Command.Parameters["@stakeholdertype"].Value = ddStType.SelectedValue.ToString();
    }


//UPDATE


    protected void sqlDSStakeholders_updating(object sender, SqlDataSourceCommandEventArgs e)
    {

        DropDownList ddStType = (DropDownList)FormView1.FindControl("ddStakeHolderType");
        e.Command.Parameters["@stakeholdertype"].Value = ddStType.SelectedValue.ToString();
    }
  



Arvixe offers ASP.net hosting that's good for testing plugins. Here is a good arvixe review if you want to know more.

Comments
Write Comments
Name  
Email    
Comments  

Other Titles