Are you sure it's returning a null value. It appears as though you're
assigning an object containing properties to an int through conversion
here:
id_vendor = Convert.ToInt32(ddlVendor.SelectedItem.Value) (and a
couple other places).

Try something alone the lines of:
id_vendor = Convert.ToInt32(ddlVendor.SelectedItem.ToString()),
This should create a string with the value you want then convert it to
the the int for passage to the variable.

>From what I can tell the DropDownList control property collection for
the Items are objects that don't contain a Value property so that's
probably where you're getting the nulls, but the object is really
there, you're just looking for the wrong property.

On May 12, 2:55 pm, Joe  Zavcer <[email protected]> wrote:
> Greetings
>
> I have been banging my head all day with this and maybe im missing
> something small.  I am not sure.  I need to grab the
> SelectedItem.Value from the drop down list on a simple form submit but
> it keeps returning null.  Can anyone point out what is wrong with this
> code.
>
> From the aspx file
>
> <asp:DropDownList ID="ddlCategory" runat="server" Font-Size="Small" /
>
>
>
> from the cs file
>
> public partial class Assets_Add : System.Web.UI.Page
> {
>     protected void Page_Load(object sender, EventArgs e)
>     {
>         if (!Page.IsPostBack)
>         {
>             BindCategories();
>             BindStatus();
>             BindVendors();
>             BindEmployees();
>         }
>
> protected void btnSubmit_Click(object sender, EventArgs e)
>     {
>
>         string test =
> Convert.ToString(ddlAssignedTo.SelectedItem.Value);
>
>         AssetManagementDataContext dc = new
> AssetManagementDataContext();
>
>         Asset asset = new Asset()
>         {
>             assetTag = txtAssetTag.Text.Trim(),
>             description = txtDescription.Text.Trim(),
>             id_employee =
> Convert.ToInt32(ddlAssignedTo.SelectedItem.Value),
>             id_category =
> Convert.ToInt32(ddlCategory.SelectedItem.Value),
>             id_status = Convert.ToInt32(ddlStatus.SelectedItem.Value),
>             id_vendor = Convert.ToInt32(ddlVendor.SelectedItem.Value),
>             model = txtModel.Text.Trim(),
>             serial = txtSerial.Text.Trim(),
>             acquired = Convert.ToDateTime(txtAcquired.Text.Trim())
>         };
>
>         dc.Assets.InsertOnSubmit(asset);
>         dc.SubmitChanges();
>     }}

Reply via email to