1.前台控件代码
通过开庭时间去显示不同的状态
//后台绑定和不绑定的却别在于DataField属性 <asp:BoundField HeaderText="状态" SortExpression="State" > <HeaderStyle Width="50px" /> </asp:BoundField> <asp:BoundField DataField="KTRQ" HeaderText="开庭日期" SortExpression="KTRQ" > <HeaderStyle Width="50px" /> </asp:BoundField>
2.在GridView1_RowDataBound方法中判断状态
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow gvr = e.Row; for (int i = 2; i < gvr.Cells.Count; i++) { try {
//0,1,2换成对应时间 if (gvr.Cells[4].Text.Trim() == "0") { gvr.Cells[9].Text = "未开庭"; } if (gvr.Cells[4].Text.Trim() == "1") { gvr.Cells[9].Text = "已开庭"; } if (gvr.Cells[4].Text.Trim() == "2") { gvr.Cells[9].Text = "已结庭"; } if (gvr.Cells[4].Text.Trim() == "") { gvr.Cells[9].Text = ""; } } catch (Exception ex) { continue; } }