gridview和textbox组合使用,更新数据——解读代码
2010-07-04 10:14
405 查看
///////前台代码/////////
<body>
<form id="form1" runat="server">
<div class="div">
<table class="tb1" border="1">
<tr class="tr1">
<th colspan="6" style="height: 10%"><span>轮胎库存数量信息表</span></th>
</tr>
<tr class="tr2">
<td style="width:5%">
<asp:Button ID="addcxj" runat="server" Text="添加" OnClick="addcxj_Click"/></td>
<td style="width: 8%">
<asp:DropDownList ID="ddl" runat="server" Width="102px">
<asp:ListItem Value="2">请选择查询项</asp:ListItem>
<asp:ListItem Value="0">库存量</asp:ListItem>
<asp:ListItem Value="1">规格</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 10%">
<asp:TextBox ID="tb" runat="server" Width="150px">请输入库存量/规格
</asp:TextBox>
</td>
<td style="width: 35%; text-align: left;">
<asp:Button ID="ssearch" runat="server" OnClick="ssearch_Click" Text="搜索" /><asp:Label ID="mess" runat="server" ForeColor="Red"></asp:Label></td>
</tr>
<tr class="tr2">
<th colspan="6" style="height: 10%">
</th>
</tr>
<tr class="tr3">
<td colspan="6" id="TD1" runat="server" style="width:100%">
<asp:GridView ID="grid_cxj" runat="server" AutoGenerateColumns="False" Width="100%" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" AllowPaging="True" OnRowCancelingEdit="grid_cxj_RowCancelingEdit" OnRowEditing="grid_cxj_RowEditing" OnRowUpdating="grid_cxj_RowUpdating" DataKeyNames="kc_id" >
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="轮胎规格">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Style="position: relative" Text='<%# Eval("ltgg") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="截止日期">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Style="position: relative" Text='<%# Eval("last_date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="库存数量">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Style="position: relative" Text='<%# Eval("lt_count") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative" Text='<%# Bind("lt_count") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="备注">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Style="position: relative" Text='<%# Eval("note") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Style="position: relative" Text='<%# Eval("kc_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:Label ID="Label6" runat="server" Font-Italic="True" ForeColor="Red" Visible="False"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
////////////////////// 后台代码 //////////////////////////////////
public partial class order_LT_KC : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
}
protected void ssearch_Click(object sender, EventArgs e)
{
string str = "";
Label6.Visible = false;
mess.Text = "";
if (ddl.SelectedItem.Value.ToString() == "2" || tb.Text == "")
{
mess.Text = "请选择查询项,写入要查询的内容!";
}
if (ddl.SelectedItem.Value.ToString() == "0")
{
int num = Convert.ToInt32(tb.Text.Trim());
str = "and lt_count >" + num;
}
else if (ddl.SelectedItem.Value.ToString() == "1")
{
str = " and ltgg like '%" + tb.Text.Trim() + '%' + "'";
}
string sql = "select * from LT_KC_INFO where kc_id>0" + str;
Excutdb.getdataset(sql, grid_cxj);
if (grid_cxj.Rows.Count == 0)
{
Label6.Visible = true;
Label6.Text = "对不起!没有符合你查询要求的数据!";
}
}
protected void addcxj_Click(object sender, EventArgs e)
{
Response.Redirect("It_kc_add.aspx");
}
protected void grid_cxj_RowEditing(object sender, GridViewEditEventArgs e)
{
grid_cxj.EditIndex = e.NewEditIndex;
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
protected void grid_cxj_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox sl;
sl = (TextBox)grid_cxj.Rows[e.RowIndex].Cells[2].Controls[1];
string oracle = "update lt_kc_info set lt_count=" + sl.Text + " where kc_id=" + grid_cxj.DataKeys[e.RowIndex].Value;
Excutdb.myBind(oracle);
grid_cxj.EditIndex = -1;
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
protected void grid_cxj_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grid_cxj.EditIndex = -1;
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
}
<body>
<form id="form1" runat="server">
<div class="div">
<table class="tb1" border="1">
<tr class="tr1">
<th colspan="6" style="height: 10%"><span>轮胎库存数量信息表</span></th>
</tr>
<tr class="tr2">
<td style="width:5%">
<asp:Button ID="addcxj" runat="server" Text="添加" OnClick="addcxj_Click"/></td>
<td style="width: 8%">
<asp:DropDownList ID="ddl" runat="server" Width="102px">
<asp:ListItem Value="2">请选择查询项</asp:ListItem>
<asp:ListItem Value="0">库存量</asp:ListItem>
<asp:ListItem Value="1">规格</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 10%">
<asp:TextBox ID="tb" runat="server" Width="150px">请输入库存量/规格
</asp:TextBox>
</td>
<td style="width: 35%; text-align: left;">
<asp:Button ID="ssearch" runat="server" OnClick="ssearch_Click" Text="搜索" /><asp:Label ID="mess" runat="server" ForeColor="Red"></asp:Label></td>
</tr>
<tr class="tr2">
<th colspan="6" style="height: 10%">
</th>
</tr>
<tr class="tr3">
<td colspan="6" id="TD1" runat="server" style="width:100%">
<asp:GridView ID="grid_cxj" runat="server" AutoGenerateColumns="False" Width="100%" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" AllowPaging="True" OnRowCancelingEdit="grid_cxj_RowCancelingEdit" OnRowEditing="grid_cxj_RowEditing" OnRowUpdating="grid_cxj_RowUpdating" DataKeyNames="kc_id" >
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="轮胎规格">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Style="position: relative" Text='<%# Eval("ltgg") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="截止日期">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Style="position: relative" Text='<%# Eval("last_date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="库存数量">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Style="position: relative" Text='<%# Eval("lt_count") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative" Text='<%# Bind("lt_count") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="备注">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Style="position: relative" Text='<%# Eval("note") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Style="position: relative" Text='<%# Eval("kc_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:Label ID="Label6" runat="server" Font-Italic="True" ForeColor="Red" Visible="False"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
////////////////////// 后台代码 //////////////////////////////////
public partial class order_LT_KC : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
}
protected void ssearch_Click(object sender, EventArgs e)
{
string str = "";
Label6.Visible = false;
mess.Text = "";
if (ddl.SelectedItem.Value.ToString() == "2" || tb.Text == "")
{
mess.Text = "请选择查询项,写入要查询的内容!";
}
if (ddl.SelectedItem.Value.ToString() == "0")
{
int num = Convert.ToInt32(tb.Text.Trim());
str = "and lt_count >" + num;
}
else if (ddl.SelectedItem.Value.ToString() == "1")
{
str = " and ltgg like '%" + tb.Text.Trim() + '%' + "'";
}
string sql = "select * from LT_KC_INFO where kc_id>0" + str;
Excutdb.getdataset(sql, grid_cxj);
if (grid_cxj.Rows.Count == 0)
{
Label6.Visible = true;
Label6.Text = "对不起!没有符合你查询要求的数据!";
}
}
protected void addcxj_Click(object sender, EventArgs e)
{
Response.Redirect("It_kc_add.aspx");
}
protected void grid_cxj_RowEditing(object sender, GridViewEditEventArgs e)
{
grid_cxj.EditIndex = e.NewEditIndex;
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
protected void grid_cxj_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox sl;
sl = (TextBox)grid_cxj.Rows[e.RowIndex].Cells[2].Controls[1];
string oracle = "update lt_kc_info set lt_count=" + sl.Text + " where kc_id=" + grid_cxj.DataKeys[e.RowIndex].Value;
Excutdb.myBind(oracle);
grid_cxj.EditIndex = -1;
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
protected void grid_cxj_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grid_cxj.EditIndex = -1;
Excutdb.getdataset("select * from lt_kc_info", grid_cxj);
}
}
相关文章推荐
- GridView里使用 DropDownList 更新数据列,不需要写一句代码
- 巧妙使用JQuery Clone 添加多行数据,并更新到数据库的实现代码
- 用户反馈信息textbox填充数据表,页面使用gridview显示反馈意见
- 创建数据库后支持的模型被更改,考虑使用代码优先更新数据库
- 巧妙使用JQuery Clone 添加多行数据,并更新到数据库的实现代码
- 巧妙使用JQuery Clone 添加多行数据,并更新到数据库的实现代码
- Android 使用RxJava+Retrofit +Realm 组合加载数据 <读取缓存 显示 请求网络数据 缓存最新数据 更新界面>(一)
- GridView使用XmlDataSource控件来操作Xml数据的更新
- 使用后台代码实现Gridview显示sql数据
- Android 使用RxJava+Retrofit +Realm 组合加载数据 <读取缓存 显示 请求网络数据 缓存最新数据 更新界面>(二)
- 如何修改本地代码,并更新到github,及其他使用技巧
- 使用layui 渲染table数据表格的实例代码
- 如何高效地使用XCodeFactory自动生成的数据层代码(一)
- oracle 更新LOBl类型数据的时候需要使用 事务
- Oracle 使用MERGE INTO 语句更新数据
- 当你使用GridView的时候,不要在page_load中绑定数据
- Excel中导入到oracle使用merge into 差异性更新数据库
- SqlServer一张表数据导入另一张表,收藏使用,工作中更新数据错误很有用
- 使用 AJAX,局部刷新 GridView 进行数据绑定的简单实现
- 如果使用追加标志O_APPEND打开一个文件以便读、写,能否仍能用lseek在任一位置开始读? 能否用lseek更新文件中任一部分的数据?