想在Gridview的Footer部分对应放置一行,增加一些TextBox 用做对数据"新增"用,但不知怎么写?
<div>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="Station.mdb" SelectCommand="SELECT * FROM [Destination]" DeleteCommand="DELETE FROM [Destination] WHERE (([StationID] = ?) OR ([StationID] IS NULL AND ? IS NULL)) AND (([Destination] = ?) OR ([Destination] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [Destination] ([StationID], [Destination], [Time], [Price], [Mileage], [BusType]) VALUES (?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [Destination] SET [Time] = ?, [Price] = ?, [Mileage] = ?, [BusType] = ? WHERE (([StationID] = ?) OR ([StationID] IS NULL AND ? IS NULL)) AND (([Destination] = ?) OR ([Destination] IS NULL AND ? IS NULL))" >
<DeleteParameters>
<asp:Parameter Name="StationID" Type="Int32" />
<asp:Parameter Name="Destination" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Time" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="Mileage" Type="String" />
<asp:Parameter Name="BusType" Type="String" />
<asp:Parameter Name="StationID" Type="Int32" />
<asp:Parameter Name="Destination" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="StationID" Type="Int32" />
<asp:Parameter Name="Destination" Type="String" />
<asp:Parameter Name="Time" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="Mileage" Type="String" />
<asp:Parameter Name="BusType" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" ShowFooter="True" DataSourceID="AccessDataSource1" AutoGenerateColumns="false" DataKeyNames="StationID,Destination"
ShowHeader="true">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="StationID" HeaderText="StationID" ReadOnly="True" SortExpression="StationID" />
<asp:BoundField DataField="Destination" HeaderText="Destination" ReadOnly="True"
SortExpression="Destination" />
<asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Mileage" HeaderText="Mileage" SortExpression="Mileage" />
<asp:BoundField DataField="BusType" HeaderText="BusType" SortExpression="BusType" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</div>
<div>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="Station.mdb" SelectCommand="SELECT * FROM [Destination]" DeleteCommand="DELETE FROM [Destination] WHERE (([StationID] = ?) OR ([StationID] IS NULL AND ? IS NULL)) AND (([Destination] = ?) OR ([Destination] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [Destination] ([StationID], [Destination], [Time], [Price], [Mileage], [BusType]) VALUES (?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [Destination] SET [Time] = ?, [Price] = ?, [Mileage] = ?, [BusType] = ? WHERE (([StationID] = ?) OR ([StationID] IS NULL AND ? IS NULL)) AND (([Destination] = ?) OR ([Destination] IS NULL AND ? IS NULL))" >
<DeleteParameters>
<asp:Parameter Name="StationID" Type="Int32" />
<asp:Parameter Name="Destination" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Time" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="Mileage" Type="String" />
<asp:Parameter Name="BusType" Type="String" />
<asp:Parameter Name="StationID" Type="Int32" />
<asp:Parameter Name="Destination" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="StationID" Type="Int32" />
<asp:Parameter Name="Destination" Type="String" />
<asp:Parameter Name="Time" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="Mileage" Type="String" />
<asp:Parameter Name="BusType" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" ShowFooter="True" DataSourceID="AccessDataSource1" AutoGenerateColumns="false" DataKeyNames="StationID,Destination"
ShowHeader="true">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="StationID" HeaderText="StationID" ReadOnly="True" SortExpression="StationID" />
<asp:BoundField DataField="Destination" HeaderText="Destination" ReadOnly="True"
SortExpression="Destination" />
<asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Mileage" HeaderText="Mileage" SortExpression="Mileage" />
<asp:BoundField DataField="BusType" HeaderText="BusType" SortExpression="BusType" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</div>
解决方案 »
- 如何读取flash中的cookie信息
- asp.net 在线用户列表
- SqlServer2005中对XML进行Value操作问题
- help!!小问题
- 找流媒体或者.net项目外包或者兼职,xdjm有时间的联系我。
- 地址编码的问题
- foreach(TextBox tb in Panel1.Controls ) //这里错误, 指定的转换无效
- 哪位大哥有没有.NET购物车源码?要自己写的,网上的都不能理解!!
- 部署到服务器的IIS上,JS效果都没了
- datagrid 选中与滚动条
- asp.net ajax框架下的pageLoad与<body onload="jsFunc()">有什么区别?
- 我做了一个404页面,我想几秒后自动跳转到上一页
<asp:GridView ID="GridView1" ShowFooter="true" BorderColor="Black" OnRowDataBound="GridView1_RowDataBound" runat="server" AutoGenerateColumns="False" Font-Size="12px" Width="530px" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="账号">
<ControlStyle Width="100px" />
<ItemTemplate>
<asp:Label ID="lbID" runat="server" Text='<%# Bind("EmpID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="姓名">
<ControlStyle Width="100px" />
<ItemTemplate>
<asp:Label ID="lbRealName" runat="server" Text='<%# Bind("EmpRealName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtRealName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<asp:Label ID="lbSex" runat="server" Text='<%# Bind("EmpSex") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlSex" runat="server">
<asp:ListItem Value="男">男</asp:ListItem>
<asp:ListItem Value="女">女</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="住址">
<ControlStyle Width="200px" />
<ItemTemplate>
<asp:Label ID="lbAddress" runat="server" Text='<%# Bind("EmpAddress") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddress" runat="server" Width="80px"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="添 加" OnClick="btnAdd_Click" />
<asp:Button ID="btnCancel" runat="server" Text="取 消" OnClick="btnCancel_Click" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Azure" Font-Size="12px" HorizontalAlign="Center" />
<RowStyle HorizontalAlign="Center" />
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
<br />
<asp:Button ID="showAdd" runat="server" Text="添 加 记 录" Width="367px" OnClick="showAdd_Click" />
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
/// <summary>
/// 数据绑定
/// </summary>
public void bind()
{
string sqlStr = "select * from Employee";
DataSet myds = Common.dataSet(sqlStr);
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "ID" };
GridView1.DataBind();
}
/// <summary>
/// 在 GridView 控件中的某个行被绑定到一个数据记录时发生。此事件通常用于在某个行被绑定到数据时修改该行的内容。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-color:Black";
}
}
//添加记录
protected void btnAdd_Click(object sender, EventArgs e)
{
TextBox empID = GridView1.FooterRow.FindControl("txtID") as TextBox;
TextBox empRealName = GridView1.FooterRow.FindControl("txtRealName") as TextBox;
DropDownList empSex = GridView1.FooterRow.FindControl("ddlSex") as DropDownList;
TextBox empAddress = GridView1.FooterRow.FindControl("txtAddress") as TextBox;
string sql = "insert into Employee(EmpID,EmpRealName,EmpSex,EmpAddress) values('" + empID.Text.ToString() + "','" + empRealName.Text.ToString() + "','" + empSex.SelectedValue.ToString() + "','" + empAddress.Text.ToString() + "')";
Common.ExecuteSql(sql);
bind();
}
//取消
protected void btnCancel_Click(object sender, EventArgs e)
{
GridView1.ShowFooter = false;
bind();
//Functions.Alert("Cancel");
}
//显示Footer
protected void showAdd_Click(object sender, EventArgs e)
{
GridView1.ShowFooter = true;
bind();
}
<asp:TemplateField HeaderText="用户ID">
<ControlStyle Width="100px" />
<ItemTemplate>
<asp:Label ID="Lb_ID" runat="Server" Text='<%# Bind("CID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_ID" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="姓名">
<ControlStyle Width="100px" />
<ItemTemplate>
<asp:Label ID="Lb_Name" runat="Server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_Name" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<asp:Label ID="Lb_Sex" runat="Server" Text='<%# Bind("Sex") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="Ddl_Sex" runat="server">
<asp:ListItem Value="男">男</asp:ListItem>
<asp:ListItem Value="女">女</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="家庭住址">
<ControlStyle Width="200px" />
<ItemTemplate>
<asp:Label ID="Lb_Address" runat="Server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_Address" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="添 加" />
<asp:Button ID="btnCancel" runat="server" Text="取 消" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
string sql = "insert into Employee(EmpID,EmpRealName,EmpSex,EmpAddress) values('" + empID.Text.ToString() + "','" + empRealName.Text.ToString() + "','" + empSex.SelectedValue.ToString() + "','" + empAddress.Text.ToString() + "')";
不怕被注入么?