如何使用gridview中的文件上传控件插入,更新和删除图像? [英] how to insert,update and delete an images using file upload control in gridview?

查看:54
本文介绍了如何使用gridview中的文件上传控件插入,更新和删除图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用gridview中的文件上传控件插入,更新和删除图像?

how to insert,update and delete an images using file upload control in gridview?

推荐答案

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>
Please Select A Brand To See its Laptop Models</h2>
<table class="style20">
<tr>
<td class="style16">
<asp:Label ID="BrandNameLabel" runat="server" Text="Brand Name"></asp:Label>
</td>
<td class="style17">
<asp:DropDownList ID="BrandNameDropDownList" runat="server" AutoPostBack="True"

Height="22px" Width="155px"

onselectedindexchanged="BrandNameDropDownList_SelectedIndexChanged">
<asp:ListItem Text="Select something" Value="-1" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style16">
<asp:Label ID="ProductNameLabel" runat="server" Text="Product Name"></asp:Label>
</td>
<td class="style17">
<asp:DropDownList ID="ProductNameDropDownList" runat="server" Width="157px"

AutoPostBack="True"

ondatabinding="ProductNameDropDownList_DataBinding"

ontextchanged="ProductNameDropDownList_TextChanged">
<asp:ListItem Text="Select something" Value="-1" />
</asp:DropDownList>
</td>
</tr>
</table>
<asp:GridView ID="GridView" runat="server" BackColor="White"

BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4"

GridLines="Horizontal" AutoGenerateColumns="False" AllowPaging="True"

PageSize="1" Width="819px" ForeColor="#003366"

AutoGenerateEditButton="True" onrowediting="GridView_RowEditing">
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Specification">
<ItemTemplate>
<asp:Label ID="Specificationlabel" runat="server" Text='<% # Eval("Specification") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="PriceLabel" runat="server" Text='<% # Eval("Price") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Instock">
<ItemTemplate>
<asp:Label ID="InstockLabel" runat="server" Text='<% # Eval("Instock") %>' />
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
<br />
<br />
<br />
<br />
</asp:Content>







using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class BrandSearchLaptop : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectioninfo"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
SqlCommand cmd1 = new SqlCommand("Select * from LaptopBrandTable", con);
SqlDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
BrandNameDropDownList.Items.Add(dr1["BrandName"].ToString());
}
con.Close();
}
}
protected void BrandNameDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
ProductNameDropDownList.Items.Clear();
String A=BrandNameDropDownList.SelectedValue;
string B = ProductNameDropDownList.SelectedValue;
if (B == "No Product Exists..")
{
GridView.DataSource = null;
GridView.DataBind();
}
else
{
con.Open();
SqlCommand cmd2 = new SqlCommand("Select * from LaptopTable Where BrandName=''" + A + "''", con);
SqlDataReader dr2 = cmd2.ExecuteReader();
ProductNameDropDownList.Items.Add("Please Select");
if (dr2.HasRows == true)
{
while (dr2.Read())
//Names collection is a combo box.
ProductNameDropDownList.Items.Add(dr2["ProductName"].ToString());
}
else
{
ProductNameDropDownList.Items.Clear();
ProductNameDropDownList.Items.Add("No Product Exists..");
GridView.DataSource = null;
GridView.DataBind();
//PriceTextBox.Text = string.Empty;
}
con.Close();
}

}
protected void ProductNameDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
void BindGrid()
{
SqlDataAdapter da = new SqlDataAdapter("select * from LaptopTable where ProductName=''" + ProductNameDropDownList.SelectedItem + "''and BrandName=''" + BrandNameDropDownList.SelectedItem + "''", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView.DataSource = ds;
GridView.DataBind();
}
protected void ProductNameDropDownList_DataBound(object sender, EventArgs e)
{
}
protected void ProductNameDropDownList_DataBinding(object sender, EventArgs e)
{
}
protected void ProductNameDropDownList_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
BindGrid();
}
}


这篇关于如何使用gridview中的文件上传控件插入,更新和删除图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆