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
Mas
NA
478
68.5k
How to bind the drop down value to grid
Feb 14 2020 3:54 AM
Hello Members,
Hope you are doing good!!
I am trying to add the dropdown value to grid...
Can any any guide me here
am adding the ASPX,CS code below
<body>
<form id=
"form1"
runat=
"server"
>
<asp:FileUpload ID=
"FileUpload1"
runat=
"server"
/>
<asp:DropDownList ID=
"Dvisa"
runat=
"server"
>
<asp:Listitem Value=
"1"
Text=
"select"
></asp:Listitem>
<asp:Listitem Value=
"2"
>1</asp:Listitem>
<asp:Listitem Value=
"3"
>2</asp:Listitem>
<asp:Listitem Value=
"4"
>3</asp:Listitem>
<asp:Listitem Value=
"5"
>4</asp:Listitem>
<asp:Listitem Value=
"6"
>5</asp:Listitem>
<asp:Listitem Value=
"7"
>6</asp:Listitem>
<asp:Listitem Value=
"8"
>7</asp:Listitem>
<asp:Listitem Value=
"9"
>8</asp:Listitem>
<asp:Listitem Value=
"10"
>9</asp:Listitem>
<asp:Listitem Value=
"11"
>10</asp:Listitem>
<asp:Listitem Value=
"12"
>11</asp:Listitem>
<asp:Listitem Value=
"13"
>12</asp:Listitem>
<asp:Listitem Value=
"14"
>13</asp:Listitem>
<asp:Listitem Value=
"15"
>14</asp:Listitem>
</asp:DropDownList>
<asp:Button ID=
"btnUpload"
runat=
"server"
Text=
"Submit"
onclick=
"btnUpload_Click"
/>
<asp:GridView ID=
"GridView1"
runat=
"server"
AutoGenerateColumns=
"False"
EmptyDataText =
"No files uploaded"
CellPadding=
"4"
EnableModelValidation=
"True"
ForeColor=
"#333333"
GridLines=
"None"
>
<AlternatingRowStyle BackColor=
"White"
ForeColor=
"#284775"
/>
<Columns>
<asp:BoundField DataField=
"Text"
HeaderText=
"File Name"
/>
<%--<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID=
"lnkDownload"
Text =
"Download"
CommandArgument =
'<%# Eval("Value") %>'
runat=
"server"
OnClick =
"DownloadFile"
></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID =
"lnkDelete"
Text =
"Delete"
CommandArgument =
'<%# Eval("Value") %>'
runat =
"server"
OnClick =
"DeleteFile"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor=
"#999999"
/>
<FooterStyle BackColor=
"#5D7B9D"
Font-Bold=
"True"
ForeColor=
"White"
/>
<HeaderStyle BackColor=
"#5D7B9D"
Font-Bold=
"True"
ForeColor=
"White"
/>
<PagerStyle BackColor=
"#284775"
ForeColor=
"White"
HorizontalAlign=
"Center"
/>
<RowStyle BackColor=
"#F7F6F3"
ForeColor=
"#333333"
/>
<SelectedRowStyle BackColor=
"#E2DED6"
Font-Bold=
"True"
ForeColor=
"#333333"
/>
</asp:GridView>
</form>
</body>
CS Code
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindGrid();
}
}
protected
void
BindGrid()
{
string
[] filePaths = Directory.GetFiles(Server.MapPath(
"~/images/"
));
List files =
new
List();
foreach
(
string
filePath
in
filePaths)
{
files.Add(
new
ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
}
protected
void
btnUpload_Click(
object
sender, EventArgs e)
{
if
(FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath(
"~/images/"
) + FileUpload1.FileName);
BindGrid();
}
else
{
Response.Write(
"Please select file to upload"
);
}
}
protected
void
DownloadFile(
object
sender, EventArgs e)
{
string
filePath = (sender
as
LinkButton).CommandArgument;
Response.ContentType = ContentType;
Response.AppendHeader(
"Content-Disposition"
,
"attachment; filename="
+ Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
protected
void
DeleteFile(
object
sender, EventArgs e)
{
string
filePath = (sender
as
LinkButton).CommandArgument;
File.Delete(filePath);
BindGrid();
}
Early response, Highly appriciated
Reply
Answers (
1
)
Pass the list of data from view to controller not working?
insert data using mvc with ef.