Hello..
i am saving a data using dropdown but i am getting a error
"Cannot implicity convert type "long" to 'String'"
- <table class="style1">
- <asp:FileUpload ID="filePath" runat="server" />
- <tr>
- <td>Category:</td>
- <td>
- <asp:DropDownList runat="server" ID="ddlWallCategry">
- </asp:DropDownList></td>
- </tr>
- </table>
- </div>
- <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- bindUsingCategory();
- }
- }
- public void bindUsingCategory()
- {
- using (WallpaperEntities10 context = new WallpaperEntities10())
- {
- ddlWallCategry.DataSource = (from r in context.WallPaperCategries select new { CategoryName = r.CategoryName, Id = r.Id }).ToList();
- ddlWallCategry.DataTextField = "CategoryName";
- ddlWallCategry.DataValueField = "Id";
- ddlWallCategry.DataBind();
- ddlWallCategry.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Select Option"));
- }
- }
- protected void btnSave_Click(object sender, EventArgs e)
- {
- Model.WallpaperCategory newusermodel = new Model.WallpaperCategory();
- string str = filePath.FileName;
- filePath.PostedFile.SaveAs(Server.MapPath("~/Upload/" + str));
- string Path = "~/Upload/" + str.ToString();
- newusermodel.Category = ddlWallCategry.SelectedIndex;
- using (var context = new WallpaperEntities10())
- {
- WallpaperRecord user = new WallpaperRecord();
- {
- string name = filePath.ToString();
- user.Category = newusermodel.Category;
- };
- var usersadd = context.Set<WallpaperRecord>();
- var response = context.WallpaperRecords.Where(u => u.Category = newusermodel.Category).FirstOrDefault();
- if (response == null)
- {
- usersadd.Add(user);
- context.SaveChanges();
- }
- }
- }