May be the value in ddl category are not proper.
On Thu, May 13, 2010 at 1:25 AM, 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();
> }
>
> }
>
--
Ravindra kumar
delhi