您的位置:首页 > 编程语言

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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐