GridView 基本使用
项目中实例一
<asp:GridView ID="gvBatchReceive" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvBatch_RowDataBound" Width="100%" EmptyDataText="无待接收立项变更"> <Columns> <asp:TemplateField> <HeaderTemplate> <input id="chkAllReceive" onclick="SelectAll(this)"; type="checkbox"><label>全选/全不选</label> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkAllReceiveChild" runat="server" /> <asp:Label ID="lblInstanceId" runat="server" Text='<%# Eval("InstanceId")%>' Visible="false"></asp:Label> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> <ItemStyle HorizontalAlign="Left" Width="120px" /> </asp:TemplateField> <asp:TemplateField HeaderText="项目"> <ItemStyle Width="45%" /> </asp:TemplateField> <asp:BoundField HeaderText="申报单位" DataField="ApplyUnitName" /> <asp:BoundField HeaderText="最后处理时间" DataField="PersistTime" DataFormatString="{0:yyyy/MM/dd HH:mm}" /> </Columns> </asp:GridView>
protected void gvBatch_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TaskItem item = (TaskItem)e.Row.DataItem; HyperLink viewlink = new HyperLink(); viewlink.Text = item.ViewAction.Name; viewlink.NavigateUrl = item.ViewAction.ActionUrl; viewlink.Attributes.Add("onclick", item.ViewAction.ActionScript); viewlink.ToolTip = item.ViewAction.Description; e.Row.Cells[1].Controls.Add(viewlink); } }