知识在于积累(.NET之路……)

导航

基于ExtAspNet下,对Grid的相关操作小结

一.在Grid相关事件或属性外的操作
1.Grid1.Columns[3].Hidden = false;//显示或隐藏Grid的第四列
2.在一个按钮点击事件中。如下:
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
     //找到Grid1中ID为“CheckBoxField1”的列,把它作为复选框列。
            ExtAspNet.CheckBoxField myCheckBoxField = Grid1.FindColumn("CheckBoxField1") as ExtAspNet.CheckBoxField;

            // 1.取得选中的值
            bool rowChecked = true;
            string upstr = "";
            string code = "";
           
            if (Grid1.Rows.Count > 0)
            {
  //遍历Grid中的每一行
                for (int i = 0; i < Grid1.Rows.Count; i++)
                {
                    rowChecked = myCheckBoxField.GetCheckState(i);
                    foreach (object key in Grid1.DataKeys[i])
                    {
                        code = key.ToString();
                    }
                }
            }
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());

        }
------------------------
        protected void Button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            if (Grid1.SelectedRowIndexArray != null && Grid1.SelectedRowIndexArray.Length > 0)
            {
                sb.Append("<span style=\"font-weight:bold;\">Following lines were selected: </span>");
                for (int i = 0, count = Grid1.SelectedRowIndexArray.Length; i < count; i++)
                {
                    int rowIndex = Grid1.SelectedRowIndexArray[i];
                    sb.AppendFormat("<br/><span style=\"font-weight:bold;\">Line {0}: </span>", rowIndex + 1);

                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
                    foreach (object key in Grid1.DataKeys[rowIndex])
                    {
                        sb.Append(key);
                        sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
                    }
                }
            }
            else
            {
                sb.Append("<span style=\"font-weight:bold;\">No line was selected.</span>");
            }

            labResult.Text = sb.ToString();
        }

---------------------------
        /// <summary>
        /// 选中第5、4、2行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button2_Click(object sender, EventArgs e)
        {
            Grid1.SelectedRowIndexArray = new int[] { 4, 3, 1 };
        }


二.在Grid相关事件或属性里的操作
1.在OnRowDataBound事件里:
        protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
        {
            //
            ExtAspNet.WindowField windowField1 = Grid1.FindColumn("WindowField1") as ExtAspNet.WindowField;
           
           
        }

2.在OnRowCommand事件里:
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            string id = Grid1.DataKeys[e.RowIndex][0].ToString();//获取Grid1中第e.RowIndex+1行的第一个DateKeyName值
            if (e.CommandName == "problem")
            {
  //弹出窗口
                Window1.Hidden = false;
                Window1.IFrameUrl = "edit.aspx?action=edit&Id=" + id;
                Window1.Title = "编辑";
            }

        }

posted on 2010-07-30 15:31  汤尼  阅读(546)  评论(0)    收藏  举报