GridView绑定完自断后怎么添加列
<asp:GridView ID="myGrid" runat="server" Width="100%" ViewStateMode="Enabled" ShowHeaderWhenEmpty="true"EmptyDataText="没有符合查询条件的数据!" ShowFooter="false">
</asp:GridView>
需求1:绑定datasouce后,怎么添加gridview的最后一列,再添加一列超链接列
(注意,我写的是自定义控件,列是不固定的!!)
需求2:大家这种情况是怎么做的? 有没有好的方法, 最好有代码!!!!! --------------------编程问答-------------------- 清加一列的用JS写就可以了
代码参考:
--------------------编程问答-------------------- GridView.Rows.add();? --------------------编程问答-------------------- <asp:GridView ID="gdvPictureList" runat="server" AutoGenerateColumns="False" Width="100%"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test_js.aspx.cs" Inherits="Project_webform.Account.test_js" %>
<!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 runat="server">
<title></title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function AddCol() {
$("tr").each(function (i) {
$(this).append("<td>" + i.toString() + "</td>");
})
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1px">
<tr>
<td>
标题1
</td>
<td>
标题2
</td>
<td>
标题3
</td>
</tr>
<tr>
<td>
行11
</td>
<td>
行12
</td>
<td>
行13
</td>
</tr>
<tr>
<td>
行21
</td>
<td>
行22
</td>
<td>
行23
</td>
</tr>
<tr>
<td>
行31
</td>
<td>
行32
</td>
<td>
行33
</td>
</tr>
</table>
<input type="button" id="btnaddcol" value="add" onclick="AddCol()" />
</div>
</form>
</body>
</html>
CellPadding="1" ForeColor="#333333" CssClass="list"
onrowdatabound="GridView1_RowDataBound"
onrowcommand="gdvPictureList_RowCommand">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" BorderColor="#DDDDDD" />
<Columns>
<asp:BoundField HeaderText="Id" DataField="Id" >
<HeaderStyle Width="30px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField>
<HeaderTemplate>
<label for="cbAll" class="checkbox-ctn" title="全选/反选"><input id="cbAll" type="checkbox" /></label>
</HeaderTemplate>
<ItemTemplate>
<label for='cbItem<%#Eval("id") %>' class="checkbox-ctn" title="选择/不选"><input type="checkbox" name="cbItem" value='<%#Eval("id") %>' id='cbItem<%#Eval("id") %>' /></label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="缩略图">
<ItemTemplate>
<a href='javascript:void(0);' onclick='javascript:showColorbox("<%#Eval("BigUrl") %>");'>
<img alt="缩略图" title="点击查看大图" src='<%#Eval("SmallUrl") %>' /></a>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:BoundField HeaderText="排序号" DataField="OrderId">
<HeaderStyle Width="50px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="排序">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" CommandName="up" CommandArgument='<%#Eval("id") %>' CssClass="button_up" ImageUrl="~/Manage/images/operate/up.gif" Width="18px" Height="18px" runat="server" />
<asp:ImageButton ID="ImageButton2" CommandName="down" CommandArgument='<%#Eval("id") %>' CssClass="button_down" ImageUrl="~/Manage/images/operate/down.gif" Width="18px" Height="18px" runat="server" />
</ItemTemplate>
<HeaderStyle Width="50px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="添加时间">
<ItemTemplate>
<%#Convert.ToDateTime(Eval("CreatedTime")).ToString("yyyy-MM-dd") %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="80px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<ItemTemplate>
<%#YDSystem.ZXF.SQLServerDAL.MasterDAL.GetNicknameByUserName(Eval("CreatedAdmin").ToString()) %>
</ItemTemplate>
<HeaderStyle Width="80px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:HyperLink ID="lnkEdit" CssClass="易做图-button" runat="server">编辑</asp:HyperLink>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate><div class="no-found">抱歉,找不到任何记录。</div></EmptyDataTemplate>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> --------------------编程问答-------------------- Refer:
http://www.cnblogs.com/insus/articles/2077538.html --------------------编程问答-------------------- 别人是要加列 不是行; 最好在绑定之前,在数据源上加列
补充:.NET技术 , ASP.NET