zoukankan      html  css  js  c++  java
  • RadioButton in GridView

    在GridView中实现RadioButton的单选功能,主要是从两个方面来考虑
    1.客户端
        在客户端来开发,我们主要考虑两个方面的问题
        1. 怎么取得GridView所在行的主键值
        2. 怎么在选定某个选项,提交给服务器以后,再能保持选项是被选上的
        这个问题可以这样解决,我们知道,在客户端,RadioButton的HTML代码是
        <input type="radio" id="***" name="**" value="*****"  />
        我们可以通过一个Literal空间,在GridView的OnRowCreated事件中动态的来控制这个的HTML代码就可以
        服务器可以通过Request.Form["**"]来得到该行记录的主键
    2.服务器端
        其原理也是修改RadioButton的HTML代码.扩张RadioButton类,写成一个服务器控件.
        相关代码如下:
        
     1using System;
     2using System.Collections.Generic;
     3using System.ComponentModel;
     4using System.Text;
     5using System.Web;
     6using System.Web.UI;
     7using System.Web.UI.WebControls;
     8
     9namespace Utilities
    10{
    11    [DefaultProperty("Text")]
    12    [ToolboxData("<{0}:GridViewRowSelector runat=\"server\"></{0}:GridViewRowSelector>")]
    13    public class GridViewRowSelector : RadioButton
    14    {
    15        protected override void Render(HtmlTextWriter writer)
    16        {
    17            GridViewRow row = (GridViewRow)this.NamingContainer;
    18            int currentIndex = row.RowIndex;
    19            GridView grid = (GridView)row.NamingContainer;
    20            this.Checked = (grid.SelectedIndex == currentIndex);
    21            this.Attributes.Add("onClick""javascript:" + Page.ClientScript.GetPostBackEventReference(grid, "Select$" + currentIndex.ToString(), true));
    22            base.Render(writer);
    23        }

    24
    25    }

        

  • 相关阅读:
    iPhone之Quartz 2D系列--编程指南(1)概览
    【Lucene3.6.2入门系列】第15节_SolrJ高亮
    项目估算与计划不是一般的难!(6)——如何跟踪计划?
    客户端MapReduce提交到YARN过程
    项目估算与计划不是一般的难!(7)——优秀项目经理是怎样炼成的?
    Properties/Property文件读取(键值均)乱码问题!
    hdu4431 Mahjong 枚举搜索。。
    weblogic 日志介绍
    dp poj 1080 Human Gene Functions
    inter
  • 原文地址:https://www.cnblogs.com/liuqhui/p/1098936.html
Copyright © 2011-2022 走看看