解决方案 »
- 关于 Flexpaper 的问题 谢谢...
- ItemDataBound
- 一个奇怪的问题:用Excel作数据源,只能读取某个字段的一部分内容
- 沙发这么好抢?沙发是什么意思?老看到这个词?
- 请帮忙,我做的网页不能局部选择字,一选就都选了,谁能告诉我是什么原因,非常感谢
- 问个菜鸟问题
- 求助!如何在用户登陆时判断该用户已经存在?
- gridview导出excel 在excel2003中打开没事,在2007就不行
- session不能保存3个汉字
- 为什么datagird不能分页错在呢里啊!
- 有没有用DevExpress的?aspxgridview问题
- 当使用服务器控件Button提交表单时不执行ajax 这是为什么!使用A标签可以执行Ajax
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;namespace zlgcSYS
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("ID"));
table.Columns.Add(new DataColumn("xm"));
table.Columns.Add(new DataColumn("km"));
table.Columns.Add(new DataColumn("je"));
table.Columns.Add(new DataColumn("sm"));
DataRow row = table.NewRow(); table.Rows.Add(row);
GridView1.DataSource = table; GridView1.DataBind();
//bind();
}
}
protected void lbtnAddRow_Click(object sender, EventArgs e)
{
DataTable table = GetGridViewData();
DataRow newRow = table.NewRow();
newRow["ID"] = Guid.NewGuid().ToString();
table.Rows.Add(newRow);
GridView1.DataSource = table;
GridView1.DataBind();
}
private DataTable GetGridViewData()
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("ID"));
table.Columns.Add(new DataColumn("xm"));
table.Columns.Add(new DataColumn("km"));
table.Columns.Add(new DataColumn("je"));
table.Columns.Add(new DataColumn("sm"));
foreach (GridViewRow row in GridView1.Rows)
{
DataRow sourseRow = table.NewRow();
sourseRow["ID"] = row.Cells[0].Text;
sourseRow["xm"] = ((DropDownList)row.Cells[3].FindControl("ddlxm")).Text;
sourseRow["km"] = ((DropDownList)row.Cells[4].FindControl("ddlkm")).Text;
sourseRow["je"] = ((TextBox)row.Cells[5].FindControl("txtje")).Text;
sourseRow["sm"] = ((TextBox)row.Cells[6].FindControl("txtsm")).Text;
table.Rows.Add(sourseRow);
}
return table;
}
protected void btnDeleteRow_Click(object sender, EventArgs e)
{
DataTable table = GetGridViewData();
foreach (GridViewRow row in GridView1.Rows)
{
if (((HtmlInputCheckBox)row.Cells[2].FindControl("chkRow")).Checked)
{
foreach (DataRow dtRow in table.Rows)
{
if (dtRow["ID"].ToString() == row.Cells[0].Text)
{
table.Rows.Remove(dtRow);
break;
}
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
} protected void Button1_Click(object sender, EventArgs e)
{
DataTable myDt = new DataTable();
myDt = GetGridViewData();
myDt.PrimaryKey = new System.Data.DataColumn[] { myDt.Columns["Id"] }; String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + System.Web.HttpContext.Current.Server.MapPath("App_Data/zlgc_Data.mdb");
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbDataAdapter adapt = new OleDbDataAdapter();
string sqlQuery = "insert into tb_Txinfo (xmId,xm,km,je,sm) values(@ID,@xm,@km,@je,@sm)";
var cmd = new OleDbCommand(sqlQuery, conn);
cmd.Parameters.Add("@xmId", OleDbType.Integer, 40, "ID");
cmd.Parameters.Add("@xm", OleDbType.VarChar, 40, "xm");
cmd.Parameters.Add("@km", OleDbType.VarChar, 20, "km");
cmd.Parameters.Add("@je", OleDbType.Integer, 40, "je");
cmd.Parameters.Add("@sm", OleDbType.VarChar, 40, "sm");
adapt.InsertCommand = cmd;
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapt);
builder.QuotePrefix = "[";
builder.QuoteSuffix = "]";
adapt.Update(myDt);
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
} }
}
http://www.cnblogs.com/insus/archive/2011/12/01/2270455.html
http://www.cnblogs.com/insus/p/3148345.html
http://www.cnblogs.com/insus/articles/1411016.html#2053183
但是因为我用的是Access数据库,所以存储过程实现不了,您的文章里的效果应该更好!
可否将源码发给我参考下?
http://www.cnblogs.com/insus/p/3247935.html
时隔太久,源码只能看那篇的评论的vb.net版本。
时隔太久,源码只能看那篇的评论的vb.net版本。好的,我再试试看吧!感谢您的指导!
//GridView设置查询刷新商品信息
查找产品的关键字:<asp:TextBox ID="tbSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="搜索" Width="44px"
onclick="btnSearch_Click" />
<asp:Button ID="btnReturn" runat="server" onclick="btnReturn_Click" Text="返回" />
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="#DEBA84"
BorderColor="#DEBA84" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="产品编号"
ShowFooter="True" Width="642px"
OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound"
onpageindexchanging="GridView1_PageIndexChanging" PageSize="5"
onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"
style="font-size: small">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
<asp:TemplateField HeaderText="产品名称">
<ItemTemplate>
<%#HightLightText((string)Eval("产品"), this.tbSearch.Text.Trim())%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="单价" HeaderText="单价" SortExpression="单价"
ReadOnly="True" />
<asp:BoundField DataField="库存量" HeaderText="库存量" SortExpression="库存量"
ReadOnly="True" />
<asp:BoundField DataField="已订购量" HeaderText="已订购量" SortExpression="已订购量"
ReadOnly="True" />
<asp:TemplateField HeaderText="订货金额" SortExpression="订货金额">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("订货金额", "{0:c}") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="OrderTotalLabel" runat="server" Font-Underline="True" ForeColor="Red"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("订货金额", "{0:c}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="是否停售">
<EditItemTemplate>
<asp:DropDownList ID="ddlSellState" runat="server" AutoPostBack="True">
<asp:ListItem Value="True">停售</asp:ListItem>
<asp:ListItem Value="False">不停售</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("SellState") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="设置" ShowEditButton="True" />
</Columns>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#C0FFC0" Font-Bold="True" ForeColor="Black" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
// strKey为原始内容,keyworld为搜索的关键字
protected string HightLightText(string strKey, string keyworld)
{
if (keyworld == "")//如果查询关键字为空返回原内容
{
return strKey;
}
string strReturn = strKey.Replace(keyworld, "<span class='highlightTxtSearch'>" + keyworld + "</span>");
return strReturn;
}
//查询关键字显示数据
protected void btnSearch_Click(object sender, EventArgs e)
{
string sqlstr = "select 产品编号, 产品, 单价, 库存量, 已订购量, 订单日期,单价 * 已订购量 AS 订货金额,CASE 是否停售 WHEN 'False' THEN '不停售' ELSE '停售' END AS SellState from tb_OrderForm where 产品 like '%" + tbSearch.Text + "%'";
sd.BindData(GridView1, sqlstr);
}
//GridView中嵌套:DropDownList设置数据
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int ID=int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
bool PaperState = bool.Parse(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlSellState")).SelectedValue);
string strsql = "UPDATE tb_OrderForm SET 是否停售 = @SellState WHERE 产品编号= @ID";
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
conn.Open();
SqlCommand comm = new SqlCommand(strsql, conn);
comm.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4));
comm.Parameters["@ID"].Value = ID;
comm.Parameters.Add(new SqlParameter("@SellState", SqlDbType.Bit, 1));
comm.Parameters["@SellState"].Value = PaperState;
if (Convert.ToInt32(comm.ExecuteNonQuery()) > 0)
{
Response.Write("<script language=javascript>alert('设置成功!');location='Default.aspx'</script>");
}
else
{
Response.Write("<script language=javascript>alert('设置失败!');location='Default.aspx'</script>");
}
//取消编辑操作
GridView1.EditIndex = -1;
//调用自定义方法DbBind()重新绑定GridView控件中信息
DbBind();
}
//其他设置(略)