62,072
社区成员
发帖
与我相关
我的任务
分享
//给GridView每一列的checkbox加客户端事件
function AddRemoveValues(oChk) {
//在处理这个地方需要注意的是:你保存的值应该具有唯一性,这样才能不会替换错误的项。
if(oChk.checked)
SelectMultiPage.HdnSelectedValues.value += "," + oChk.value;
else
SelectMultiPage.HdnSelectedValues.value = SelectMultiPage.HdnSelectedValues.value.replace("," + oChk.value,"");
}
<asp:GridView id="base_gvMain" runat="server" Width="100%" ShowFooter="false" PageSize="8" DataKeyNames="F_User_ID,F_User_Name" CssClass="GridTable" CellPadding="3" AutoGenerateColumns="False" AllowPaging="True" OnRowDataBound="base_gvMain_RowDataBound">
<SelectedRowStyle CssClass="GridSelectedItem" />
<AlternatingRowStyle BackColor="#DEDEDE" CssClass="GridAlterItem" />
<RowStyle CssClass="GridItem" HorizontalAlign="Center" />
<HeaderStyle CssClass="GridHeader" />
<FooterStyle CssClass="GridFooter" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" runat="server" id="chkSelect" onclick="AddRemoveValues(this)"
value='<%#DataBinder.Eval(Container.DataItem,"F_User_Name")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="F_User_Name" HeaderText="姓名" SortExpression="F_User_Name"></asp:BoundField>
<asp:BoundField DataField="F_Position" HeaderText="职务" SortExpression="F_Position"></asp:BoundField>
<asp:BoundField DataField="F_Telphone" HeaderText="联系电话" SortExpression="F_Telphone"></asp:BoundField>
</Columns>
<PagerSettings Visible="False" />
</asp:GridView>
#region 得到辅修人
protected void ibtnSure_Click(object sender, ImageClickEventArgs e)
{
try
{
if (HdnSelectedValues.Value.Length == 0)
{
Alert("您还没选择辅修人员,请您选择要返回的辅修人!");
return;
}
string strGetMaintainMan = HdnSelectedValues.Value.TrimEnd(',').TrimStart(',');
string script = @"var GetData = '" + strGetMaintainMan + "';window.returnValue = GetData;window.close();";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", script, true);
}
catch (Exception ex)
{
Alert(ex.Message);
}
}
#endregion
#region 分页时记录状态
protected void base_gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (string selectvalue in HdnSelectedValues.Value.Split(','))
{
if (selectvalue == this.base_gvMain.DataKeys[e.Row.RowIndex].Values["F_User_Name"].ToString())
{
HtmlInputCheckBox ChkSelected = (HtmlInputCheckBox)(e.Row.FindControl("chkSelect"));
ChkSelected.Checked = true;
}
}
}
}
#endregion
/// <summary>
/// 递归得到选择节点的Text和Value
/// by liuqingjun
/// </summary>
/// <param name="node">树的节点</param>
private void GetCheckedValue(TreeNode node)
{
if (node == null)
{
foreach (TreeNode treeNode in this.TV_Select.Nodes)
{
if (treeNode.Checked)
{
this.hidName.Value += treeNode.Text.Trim() + ",";
this.hidID.Value += treeNode.Value + ",";
}
if (treeNode.ChildNodes.Count > 0)
{
GetCheckedValue(treeNode);
}
}
}
else
{
foreach (TreeNode treeNode in node.ChildNodes)
{
if (treeNode.Checked)
{
this.hidName.Value += treeNode.Text.Trim() + ",";
this.hidID.Value += treeNode.Value + ",";
}
if (treeNode.ChildNodes.Count > 0)
{
GetCheckedValue(treeNode);
}
}
}
}
/// <summary>
/// 给选择该对话框的页面返回值
/// by liuqingjun
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelect_ServerClick(object sender, EventArgs e)
{
this.hidID.Value = string.Empty;
this.hidName.Value = string.Empty;
GetCheckedValue((TreeNode)null);
if (this.hidID.Value == string.Empty)
{
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(this.GetType(), "", "alert('请您选择信息');", true);
}
else
{
this.hidID.Value = this.hidID.Value.Substring(0, this.hidID.Value.Length - 1);
this.hidName.Value = this.hidName.Value.Substring(0, this.hidName.Value.Length - 1);
if ((string)ViewState["SelectMode"] == "Single")
{
if (this.hidID.Value.Split(',').Length > 1)
{
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(this.GetType(), "", "alert('你只能选择一项目信息,不能多选');", true);
return;
}
}
string script = "var nodeInfo = new Array(2);nodeInfo[0] = '" + this.hidID.Value + "';nodeInfo[1] = '" + this.hidName.Value + "';window.returnValue = nodeInfo;window.close();";
ClientScriptManager returnvalue = Page.ClientScript;
returnvalue.RegisterStartupScript(this.GetType(), "", script, true);
}
}
<div>
<a href="#TreeView1_SkipLink"><img alt="跳过导航链接。" src="/WebSite5/WebResource.axd?d=A6pKNurI8cZBe9bKHOa6bQ2&t=633471415347187500" width="0" height="0" style="border-width:0px;" /></a><div id="TreeView1" style="height:90%;width:170px;position: relative">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><a id="TreeView1n0" href="javascript:TreeView_ToggleNode(TreeView1_Data,0,TreeView1n0,' ',TreeView1n0Nodes)"><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqvek9cb93Fx__XXIAt-v3A01&t=633471415347187500" alt="折叠 新建节点" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t0');" id="TreeView1t0">新建节点</a></td>
</tr>
</table><div id="TreeView1n0Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><a id="TreeView1n1" href="javascript:TreeView_ToggleNode(TreeView1_Data,1,TreeView1n1,' ',TreeView1n1Nodes)"><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqvek9cb93Fx__XXIAt-v3A01&t=633471415347187500" alt="折叠 新建节点" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点\\新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t1');" id="TreeView1t1">新建节点</a></td>
</tr>
</table><div id="TreeView1n1Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"></div></td><td><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqneje2bfwtopj9ylkfZPJuE1&t=633471415347187500" alt="" /></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点\\新建节点\\新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t2');" id="TreeView1t2">新建节点</a></td>
</tr>
</table>
</div>
</div><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><a id="TreeView1n3" href="javascript:TreeView_ToggleNode(TreeView1_Data,3,TreeView1n3,' ',TreeView1n3Nodes)"><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqvek9cb93Fx__XXIAt-v3A01&t=633471415347187500" alt="折叠 新建节点" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t3');" id="TreeView1t3">新建节点</a></td>
</tr>
</table><div id="TreeView1n3Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqneje2bfwtopj9ylkfZPJuE1&t=633471415347187500" alt="" /></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点\\新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t4');" id="TreeView1t4">新建节点</a></td>
</tr>
</table>
</div><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><a id="TreeView1n5" href="javascript:TreeView_ToggleNode(TreeView1_Data,5,TreeView1n5,' ',TreeView1n5Nodes)"><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqvek9cb93Fx__XXIAt-v3A01&t=633471415347187500" alt="折叠 新建节点" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t5');" id="TreeView1t5">新建节点</a></td>
</tr>
</table><div id="TreeView1n5Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqneje2bfwtopj9ylkfZPJuE1&t=633471415347187500" alt="" /></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点\\新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t6');" id="TreeView1t6">新建节点</a></td>
</tr>
</table>
</div><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><a id="TreeView1n7" href="javascript:TreeView_ToggleNode(TreeView1_Data,7,TreeView1n7,' ',TreeView1n7Nodes)"><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqvek9cb93Fx__XXIAt-v3A01&t=633471415347187500" alt="折叠 新建节点" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t7');" id="TreeView1t7">新建节点</a></td>
</tr>
</table><div id="TreeView1n7Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqneje2bfwtopj9ylkfZPJuE1&t=633471415347187500" alt="" /></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点\\新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t8');" id="TreeView1t8">新建节点</a></td>
</tr>
</table>
</div><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqneje2bfwtopj9ylkfZPJuE1&t=633471415347187500" alt="" /></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t9');" id="TreeView1t9">新建节点</a></td>
</tr>
</table><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><img src="/WebSite5/WebResource.axd?d=yc7X5sc7fLVtRpfSXrhcqneje2bfwtopj9ylkfZPJuE1&t=633471415347187500" alt="" /></td><td style="white-space:nowrap;"><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s新建节点')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t10');" id="TreeView1t10">新建节点</a></td>
</tr>
</table>
</div><a id="TreeView1_SkipLink"></a>
<input type="submit" name="Button2" value="确定(服务器)" id="Button2" style="left: 47px;
position: relative; top: 0px" />
<input id="Button1" style="position: relative; left: -114px; top: 0px;" type="button" value="确定" onclick="selectCode()"/>
</div>