1: <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridView.ascx.cs" Inherits="Shared.UserControls.GridView" %>
2: <%@ Import Namespace="System.Reflection" %>
3: <% 1: -- style code --
%>
4: <style type="text/css">
5: .gridView
6: { 7: border-collapse: collapse;
8: }
9: .gridView th, .gridView td
10: { 11: padding: 5px;
12: }
13: .gridView th
14: { 15: border-bottom: double 3px black;
16: }
17: .gridView td
18: { 19: border-bottom: solid 1px black;
20: }
21: .alternatingItem
22: { 23: background-color: lightgrey;
24: }
25: </style>
26: <% 1: -- Javascripts code --
%>
27: <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script> 1:
2: <%--<script src="../../Scripts/jquery-1.3.2-vsdoc.js" type="text/javascript">
1: </script>--%>
2: <script type="text/javascript">
3: var controller = '';
4: var SaveAction = '';
5: <% GetController(); GetSaveAction(); %>
6: function IsValidAction(ctrl, actn)
7: { 8: if(($.trim(ctrl) == '') || ($.trim(actn) == ''))
9: return false;
10: else
11: return true;
12: }
13: function SaveAllClick() { 14: //debugger;
15: if(!IsValidAction(controller,SaveAction))
16: { 17: alert("Error while saving data"); 18: return;
19: }
20: var i = 0;
21: var inputs = new Array();
22: $("#BaseTable").find("input").each(function() { 23: inputs[i] = [this.id, this.value];
24: i++;
25: });
26:
27: var columnsCount = $("#BaseTable").find("th").length; 28: $.post("/"+controller+"/"+SaveAction, { inputs: inputs, columnsCount: columnsCount }); 29: Border();
30: $("#ChangeFlag").text(""); 31: $("#SaveAll").attr("disabled", "disabled"); 32: alert("Saved"); 33: }
34: var prevCell;
35: function Border(cell) { 36: if (prevCell != null) { 37: $(prevCell).attr("style", "border-style: none"); 38: }
39: if (cell != null) { 40: var i = $(cell); //.find("input"); 41: i.attr("style", "border-style: inset"); 42: }
43: prevCell = cell;
44: }
45: function Unborder(cell) { 46: if (cell != null) { 47: var i = $(cell); //.find("input"); 48: i.attr("style", "border-style: none"); 49: }
50: }
51: function MarkChanges() { 52: $("#ChangeFlag").text("Page should be saved"); 53: $("#SaveAll").removeAttr("disabled"); 54: }
</script>
28: <% 1: -- Show the Headers --
%>
29: <table class="gridView" id="BaseTable">
30: <thead>
31: <tr>
32: <% 1: foreach (PropertyInfo prop in this.Columns)
2: { %>
33: <th>
34: <% 1: = prop.Name
%>
35: </th>
36: <% 1: }
%>
37: </tr>
38: </thead>
39: <% 1: -- Show the Rows --
%>
40: <tbody>
41: <% 1: foreach (object row in this.Rows)
2: { %>
42: <tr class="<%= this.FlipCssClass( "item", "alternatingItem") %>">
43: <% 1: -- Show Each Column --
%>
44: <% 1: foreach (PropertyInfo prop in this.Columns)
2: { %>
45: <td>
46: <% 1: var typeCode = Type.GetTypeCode(prop.PropertyType);
%>
47: <% 1: var str_disabled = "";
2: if (this.GetAtt(prop.Name))
3: str_disabled = "disabled=\"disabled\"";
4:
%>
48: <% 1: -- String Columns --
%>
49: <% 1: if (typeCode == TypeCode.String)
2: { %>
50: <input id="<%=prop.Name %>" type="text" style="border-style: none" value="<%= GetColumnValue(row, prop.Name)%>"
51: onmousedown="Border(this)" onselect="Border(this)" onblur="Unborder(this)" onchange="MarkChanges()"
52: <%= str_disabled %> />
53: <% 1: }
%>
54: <% 1: -- DateTime Columns --
%>
55: <% 1: if (typeCode == TypeCode.DateTime)
2: { %>
56: <input id="<%=prop.Name %>" type="text" style="border-style: none" value="<%= GetColumnValue(row, prop.Name, "{0:D}")%>" 57: onmousedown="Border(this)" onselect="Border(this)" onblur="Unborder(this)" onchange="MarkChanges()"
58: <%= str_disabled %> />
59: <% 1: }
%>
60: <% 1: -- Decimal Columns --
%>
61: <% 1: if (typeCode == TypeCode.Decimal)
2: { %>
62: <input id="<%=prop.Name %>" type="text" style="border-style: none" value="<%= GetColumnValue(row, prop.Name, "{0:f}") %>" 63: onmousedown="Border(this)" onselect="Border(this)" onblur="Unborder(this)" onchange="MarkChanges()"
64: <%= str_disabled %> />
65: <% 1: }
%>
66: <% 1: -- Decimal Columns --
%>
67: <% 1: if (typeCode == TypeCode.Double)
2: { %>$
68: <input id="<%=prop.Name %>" type="text" style="border-style: none" value="<%= GetColumnValue(row, prop.Name, "{0:f}") %>" 69: onmousedown="Border(this)" onselect="Border(this)" onblur="Unborder(this)" onchange="MarkChanges()"
70: <%= str_disabled %> />
71: <% 1: }
%>
72: <% 1: -- Boolean Columns --
%>
73: <% 1: if (typeCode == TypeCode.Boolean)
2: { %>
74: <% 1: if ((bool)(this.GetColumnValue(row, prop.Name)))
2: { %>
75: <input type="checkbox" disabled="disabled" checked="checked" />
76: <% 1: }
2: else
3: { %>
77: <input type="checkbox" disabled="disabled" />
78: <% 1: }
%>
79: <% 1: }
%>
80: <% 1: -- Integer Columns --
%>
81: <% 1: if (typeCode == TypeCode.Int32)
2: { %>
82: <input id="<%=prop.Name %>" type="text" style="border-style: none" value="<%= GetColumnValue(row, prop.Name)%>"
83: onmousedown="Border(this)" onselect="Border(this)" onblur="Unborder(this)" onchange="MarkChanges()"
84: <%= str_disabled %> />
85: <% 1: }
%>
86: </td>
87: <% 1: }
%>
88: </tr>
89: <% 1: }
%>
90: </tbody>
91: </table>
92: <p>
93: <input id="SaveAll" disabled="disabled" type="button" value="Save" onclick="SaveAllClick()" />
94: <span id="ChangeFlag"></span>
95: </p>