读书人

2个有关问题js和gridview

发布时间: 2012-01-09 21:05:42 作者: rapoo

2个问题js和gridview
1。我在gridview放了checkbox全选的列,可是运行后,该列没有显示
代码如下
<asp:GridView ID= "gvComUnion " runat= "server " AllowPaging= "True " AutoGenerateColumns= "False "
BackColor= "White " BorderColor= "#3366CC " BorderStyle= "Solid " BorderWidth= "1px "
CellPadding= "4 " Font-Size= "12px " HorizontalAlign= "Left " OnPageIndexChanging= "gvParty_PageIndexChanging "
OnRowEditing= "gvParty_RowEditing " PageSize= "15 " Width= "556px " OnRowDataBound= "gvParty_RowDataBound " OnLoad= "gvParty_Load " OnRowCreated= "gvParty_RowCreated " Font-Names= "宋体 " OnSelectedIndexChanged= "gvComUnion_SelectedIndexChanged " >
<PagerSettings FirstPageText= "第一页 " LastPageText= "最后一页 " Mode= "NextPreviousFirstLast "
NextPageText= "下一页 " PreviousPageText= "上一页 "/>
<FooterStyle BackColor = "#EFEFEF " ForeColor = "#000D47 " />
<Columns>

<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID= "CheckBox1 " runat= "server " Text= "全选 " AutoPostBack= "true " OnCheckedChanged= "CheckAll " />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID= "ItemCheckBox " runat= "server " />
</ItemTemplate>
</asp:TemplateField>


<asp:BoundField DataField= "COMID " HeaderText= "会员编号 "/>
<asp:BoundField DataField= "COMNAME " HeaderText= "单位名称 " />
<asp:BoundField DataField= "COMINLOW " HeaderText= "所有制 " />
<asp:BoundField DataField= "BUSINESS " HeaderText= "行业 " />


<asp:BoundField DataField= "DISTRICT " HeaderText= "所在区 " />
<asp:BoundField DataField= "STATUS " HeaderText= "状态 " />
<asp:CommandField EditText= "详细信息 " HeaderText= "详细信息 " ShowEditButton= "True " />

</Columns>

<RowStyle ForeColor= "#003399 " HorizontalAlign= "Center " />
<SelectedRowStyle BackColor= "#003399 " Font-Bold= "True " ForeColor= "#CCFF99 " />
<PagerStyle BackColor= "#EFEFEF " ForeColor= "#003399 " HorizontalAlign= "Right " />
<HeaderStyle BackColor= "#003399 " BorderStyle= "None " Font-Bold= "True " ForeColor= "White " />
<AlternatingRowStyle BackColor= "#EFEFEF " />

</asp:GridView>


问题2;
引用代码如下
<input id= "Text1 " type= "text " onclick= "return showCalendar( 'Text1 ', 'y-mm-dd '); " onfocus= "return showCalendar( 'Text1 ', 'y-mm-dd '); " /> 此处不能换行 <img src= "../images/1.gif " alt= "选择日期 " width= "25px " height= "21px " style= "CURSOR: hand " onclick= "return showCalendar( 'Text1 ', 'y-mm-dd '); " />
其中不能换行,否则运行无效,不知道为什么

[解决办法]
给你个好的:

<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox ID= "CheckBox1 " runat= "server " />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID= "chbitem " runat= "server " />
</ItemTemplate>
<HeaderTemplate>
<input id= "chkAll " onclick= "javascript:SelectAllCheckboxes(this); "
runat= "server " type= "checkbox " />
</HeaderTemplate>
</asp:TemplateField>


function SelectAllCheckboxes(spanChk){

// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox= (spanChk.type== "checkbox ") ?
spanChk : spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;

for(i=0;i <elm.length;i++)


if(elm[i].type== "checkbox " &&
elm[i].id!=theBox.id)
{
//elm[i].click();
if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;
}
}

读书人网 >asp.net

热点推荐