Gridview中Dropdownlist的刷新有关问题
Gridview中Dropdownlist的刷新问题
因为要动态增加行,所以上网找了好久,才找到神贴
http://www.cnblogs.com/psforever/archive/2011/02/23/1963207.html
但是因为我这里面要用到Dropdownlist,数据绑定没做起来,就做成了静态的ListItem,目前功能基本实现,但是每次增加行的时候,Dropdownlist内容又恢复原始状态,实在搞不定了,求教各位大神!
如果能帮小弟动态绑定Dropdownlist,感激不尽!
页面代码:
------解决思路----------------------
或者你可以视每一行为一个对象,所有创建一行,就是创建一个对象,显示再显示此对象内容即可:
http://www.cnblogs.com/insus/p/3247935.html
因为要动态增加行,所以上网找了好久,才找到神贴
http://www.cnblogs.com/psforever/archive/2011/02/23/1963207.html
但是因为我这里面要用到Dropdownlist,数据绑定没做起来,就做成了静态的ListItem,目前功能基本实现,但是每次增加行的时候,Dropdownlist内容又恢复原始状态,实在搞不定了,求教各位大神!
如果能帮小弟动态绑定Dropdownlist,感激不尽!
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="zlgcSYS.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>GridView中实现动态动态增加删除行</title>
<style type="text/css">
.hide{
display:none;
}
</style>
<script type="text/javascript">
//选中所有行
function SelectAll(chkAll)
{
var gridview = document.getElementById("GridView1");
if (gridview)
{
//获取到GridView1中的所有input标签
var inputs = gridview.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++)
{
if (inputs[i].type=="checkbox")
{
//设置所有checkbox的选中状态与chkAll一致
inputs[i].checked = chkAll.checked;
}
}
}
}
//给选中行换背景色
function checkRow(chkRow)
{
var row = chkRow.parentNode.parentNode;
if(row)
{
if (chkRow.checked)
row.style.backgroundColor="#7799CC";
else
row.style.backgroundColor="#FFFFFF";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="lbtnAddRow" runat="server" Width="80px" OnClick="lbtnAddRow_Click">添加行</asp:LinkButton>
<asp:LinkButton ID="btnDeleteRow" runat="server" OnClick="btnDeleteRow_Click" OnClientClick="return confirm('确定要删除选中行吗?');">删除选中行</asp:LinkButton>
</div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" >
<ItemStyle CssClass="hide" BorderColor="#507CD1" />
<HeaderStyle CssClass="hide" />
</asp:BoundField>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# Container.DataItemIndex + 1%>
</ItemTemplate>
<ItemStyle BorderColor="#507CD1" HorizontalAlign="Center" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<input id="chkAll" type="checkbox" onclick="SelectAll(this)" />
</HeaderTemplate>
<ItemTemplate>
<input id="chkRow" type="checkbox" onclick="checkRow(this);" runat="server" />
</ItemTemplate>
<ItemStyle Width="30px" HorizontalAlign="Center" BorderColor="#507CD1" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="经费项目">
<ItemTemplate>
<asp:DropDownList ID="ddlxm" runat="server" AutoPostBack="True">
<asp:ListItem>调研差旅费</asp:ListItem>
<asp:ListItem>管理费</asp:ListItem>
<asp:ListItem>会议费</asp:ListItem>
<asp:ListItem>劳务费</asp:ListItem>
<asp:ListItem>设备购置和使用费</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="100px" BorderColor="#507CD1" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="经济科目">
<ItemTemplate>
<asp:DropDownList ID="ddlkm" runat="server" AutoPostBack="True">
<asp:ListItem>印刷费</asp:ListItem>
<asp:ListItem>咨询费</asp:ListItem>
<asp:ListItem>劳务费</asp:ListItem>
<asp:ListItem>差旅费</asp:ListItem>
<asp:ListItem>邮电费</asp:ListItem>
<asp:ListItem>专用设备购置费</asp:ListItem>
<asp:ListItem>会议费</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="100px" BorderColor="#507CD1" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="输入金额">
<ItemTemplate>
<asp:TextBox ID="txtje" runat="server" Text='<%# Bind("je") %>' BorderStyle="None"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" BorderColor="#507CD1" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="支出说明">
<ItemTemplate>
<asp:TextBox ID="txtsm" runat="server" Text='<%# Bind("sm") %>' BorderStyle="None"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" BorderColor="#507CD1" BorderWidth="1px" />
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
------解决思路----------------------
或者你可以视每一行为一个对象,所有创建一行,就是创建一个对象,显示再显示此对象内容即可:
http://www.cnblogs.com/insus/p/3247935.html