我的gridview中有两个模板列 一列是linkbutton 一列是celender日历.我的linkbutton 里面OnClick="lbnDailyCustomize_Click“  。当程序执行到lbnDailyCustomize_Click里面的时候如何找到相同row的 摸板列的celender的日期的取值呢?
另外模板列里的(linkbutton)sender 的parentcontrol是cell,cell 的parent 是什么?clumn 还是row? 谢谢

解决方案 »

  1.   

    cell 的parent 是row,根据这个就能取到你要的东西.
      

  2.   

    传过来的sender就是点击的LinkButton控件,Parent是DataControlField,DataControlField的Parent是GridViewRow,在GridViewRow中用FindControl来找你的celender,然后取值
      

  3.   

    上面说的DataControlField应为DataControlFieldCell,以下是代码
    LinkButton theLinkButton = (LinkButton)sender;
    DataControlFieldCell theCell = (DataControlFieldCell)theLinkButton.Parent;
    GridViewRow theRow = (GridViewRow)theCell.Parent;
    在theRow中用FindControl找你的日历控件
      

  4.   

    protected void lbnDailyCustomize_Click(object sender, EventArgs e)
        {
            LinkButton lbtn = sender as LinkButton;
            lbtn.ForeColor = System.Drawing.Color.Red;//找到当前的按钮        GridViewRow row = lbtn.Parent.Parent as GridViewRow;//找到当前行
            Calendar cad = row.FindControl("Calendar1") as Calendar ;
            cad.Visible = false;//可以访问当前行的日历控件了
           
            int curIndex = row.RowIndex;//当前行号
            //.....
        }