TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
271
36.7k
save data using dropdown in asp.net Entity Framework
Aug 14 2020 3:51 AM
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;
//getting error in this line
};
var usersadd = context.Set<WallpaperRecord>();
var response = context.WallpaperRecords.Where(u => u.Category = newusermodel.Category).FirstOrDefault();
if
(response ==
null
)
{
usersadd.Add(user);
context.SaveChanges();
}
}
}
Reply
Answers (
3
)
How to write another language font in asp.net core ?
Use datagridview columns added from the designer on data table