相关笔记
-工作笔记-Gridview部分
-工作笔记-Datatable部分
-工作笔记-字段处理部分
-工作笔记-数据验证和数据传输
-工作笔记-SQL语句部分
-工作笔记-页面样式部分
-工作笔记-Winform部分
-工作笔记-文件处理部分
-工作笔记-下拉列表部分
-工作笔记-存储过程部分
1.Js部分
1)gridview中checkbox按照值是否选中
Js代码
<script type="text/javascript">
function checkAll(isChecked) {//实现全选
var gridView1 = document.getElementById('gridview的id');
for (var i = 1; i < gridView1.rows.length; i++) {
if (gridView1.rows[i].cells[checkbox在第几列就写几].getElementsByTagName("INPUT")[0].disabled == true) {
//input的没有Enabled要写成disabled
gridView1.rows[i].cells[13].getElementsByTagName("INPUT")[0].checked= false;
}
else {
gridView1.rows[i].cells[13].getElementsByTagName("INPUT")[0].checked = isChecked;
}
}
}
</script>
Html代码
<asp:TemplateField>
<HeaderTemplate>
<input id="cbAll" onclick="checkAll(this.checked)" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbSelect" runat="server" CommandArgument='<%# Eval("id")%>' Enabled='<%# bool.Parse(Eval("Receive_AuditingState").ToString()!= "0" ? "True" : "false") %>'/>//0为不可用
<asp:Button runat="server" ID="btndele" title="删除" CssClass="btndele" OnClientClick="return IfDelete()" CommandArgument='<%#
Eval("id")%>' Style="display: none;" />
</ItemTemplate>
<HeaderStyle Width="30px" />
<ItemStyle CssClass="GridViewClo" HorizontalAlign="Center"/>
</asp:TemplateField>
2.后台部分
1)gridview相同的列合并,写在PreRender事件中
protected void GridView的id名_PreRender(object sender, EventArgs e)
{
for (int rowIndex = GridView的id名.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = GridView的id名.Rows[rowIndex];
GridViewRow previousRow = GridView的id名.Rows[rowIndex+1];
if (row.Cells[1].Text == previousRow.Cells[1].Text)
{
row.Cells[1].RowSpan = previousRow.Cells[1].RowSpan<2 ? 2 :
previousRow.Cells[1].RowSpan+1;
previousRow.Cells[1].Visible = false;
}
}//第一列合并
for (int rowIndex = GridView的id名.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = GridView的id名.Rows[rowIndex];
GridViewRow previousRow = GridView的id名.Rows[rowIndex+1];
if (row.Cells[2].Text == previousRow.Cells[2].Text)
{
if (!previousRow.Cells[1].Visible)
{
row.Cells[2].RowSpan = previousRow.Cells[2].RowSpan < 2 ? 2 :previousRow.Cells[2].RowSpan+1;
previousRow.Cells[2].Visible = false;
}
}
}//第二列合并且第一列相同第二列才合并
}
2)gridview中的超链接调用js
1.js方法
function guestedit(obj, school, lou, louceng, classname) {
Window_Open(obj, 1, '../student/DormitoryFBCount.aspx?school=' + school + '&lou=' + lou + '&louceng=' + louceng + '&classname='+classname, 500, 320);
}
2.html代码
<asp:TemplateField HeaderText="楼层" SortExpression="SuShe_LouCeng">
<ItemTemplate>
方法一:<span><a style="cursor:pointer;" href=" javascript:guestedit(this,'<%# Eval("SuShe_School")%>','<%# Eval("SuShe_Lou")%>','<%# Eval("SuShe_LouCeng")%>','1')"><%# Eval("SuShe_LouCeng")%></a> </span>
方法二:<a style='color:red; cursor:pointer;' onclick="guestedid(this,'<%# Eval("ClassInfo_Number") %>','<%# Eval("ClassInfo_Grade") %>');"><%# Eval("Student_ClassNamecount")%></a>
</ItemTemplate>
<HeaderStyle Width="60px" />
<ItemStyle CssClass="GridViewClo" />
</asp:TemplateField>
<asp:BoundField DataField="SuShe_ClassName" HeaderText="班级" SortExpression="SuShe_ClassName">
<HeaderStyle Width="120px" />
<ItemStyle CssClass="GridViewClo" />
</asp:BoundField>
3)超链接显示
cursor:pointer;
4)ridview添加指定列
GridView.Columns.Insert(8,fileld);
5)Gridview添加列 每列实例化一次
BoundField fileld = new BoundField();
fileld.DataField = "数据名称";
fileld.HeaderText = "维修部门";
fileld.SortExpression = "数据名称";
GridView1.Columns.Insert(1,fileld); or
GridView1.Columns.Add(fileld);
6)后台调用前台css
GridView1.CssClass = "样式名字";
7)给一行加样式
fileld1.ItemStyle.CssClass = "GridViewClo";
8)设置每行的宽度不加px
fileld1.HeaderStyle.Width = 100;
9)Gridview删除指定列
GridView1.Columns.RemoveAt(fileld);
10)Gridview删除所有
GridView1.Columns.Clear();
11) 隐藏指定列
this.GridView1.Columns[4].Visible = false;
12) 循环读取gridview第四列的值
foreach (GridViewRow gvr in GridView的ID.Rows)
{
string a = "'" + gvr.Cells[3].Text + "'";
}
12)gridview中字体居中
<ItemStyle HorizontalAlign="Center" />