Beispiel #1
0
        private void ShowData(string strSql)
        {
            string         strConn = ConfigurationSettings.AppSettings["strConn"];
            SqlConnection  SqlConn = new SqlConnection(strConn);
            SqlDataAdapter SqlCmd  = new SqlDataAdapter(strSql, SqlConn);
            DataSet        SqlDS   = new DataSet();

            SqlCmd.Fill(SqlDS, "NewsInfo");
            RowNum = DataGridNews.CurrentPageIndex * DataGridNews.PageSize + 1;
            LinNum = 0;

            string SortExpression = DataGridNews.Attributes["SortExpression"];
            string SortDirection  = DataGridNews.Attributes["SortDirection"];

            SqlDS.Tables["NewsInfo"].DefaultView.Sort = SortExpression + " " + SortDirection;

            DataGridNews.DataSource = SqlDS.Tables["NewsInfo"].DefaultView;
            DataGridNews.DataBind();
            for (int i = 0; i < DataGridNews.Items.Count; i++)
            {
                Label labNewsTitle = (Label)DataGridNews.Items[i].FindControl("labNewsTitle");
                labNewsTitle.Text = Server.HtmlEncode(labNewsTitle.Text);
                if (labNewsTitle.Text.Trim().Length > 30)
                {
                    labNewsTitle.Text = labNewsTitle.Text.Trim().Substring(0, 30) + "...";
                }
                //labNewsTitle.Text=ObjFun.getStr(labNewsTitle.Text.Trim(),30)+"...";

                LinkButton LBEditNews = (LinkButton)DataGridNews.Items[i].FindControl("LinkButEditNews");
                LinkButton LBDel      = (LinkButton)DataGridNews.Items[i].FindControl("LinkButDel");

                if ((myLoginID.Trim().ToUpper() == "ADMIN") || (myLoginID.Trim().ToUpper() == DataGridNews.Items[i].Cells[5].Text.Trim().ToUpper()))
                {
                    LBEditNews.Attributes.Add("onclick", "javascript:jscomNewOpenByFixSize('EditNews.aspx?NewsID=" + DataGridNews.Items[i].Cells[0].Text + "','IssuNews',780,650); return false;");
                    LBDel.Attributes.Add("onclick", "javascript:{if(confirm('确定要删除选择新闻吗?')==false) return false;}");
                }
                else
                {
                    LBEditNews.Attributes.Add("onclick", "javascript:alert('对不起,您没有此操作权限!');return false;");
                    LBDel.Attributes.Add("onclick", "javascript:alert('对不起,您没有此操作权限!');return false;");
                }
            }
            LabelRecord.Text      = Convert.ToString(SqlDS.Tables["NewsInfo"].Rows.Count);
            LabelCountPage.Text   = Convert.ToString(DataGridNews.PageCount);
            LabelCurrentPage.Text = Convert.ToString(DataGridNews.CurrentPageIndex + 1);
            SqlConn.Dispose();
        }
Beispiel #2
0
        private void ShowData(string strSql)
        {
            string         strConn = ConfigurationSettings.AppSettings["strConn"];
            SqlConnection  SqlConn = new SqlConnection(strConn);
            SqlDataAdapter SqlCmd  = new SqlDataAdapter(strSql, SqlConn);
            DataSet        SqlDS   = new DataSet();

            SqlCmd.Fill(SqlDS, "NewsInfo");
            RowNum = DataGridNews.CurrentPageIndex * DataGridNews.PageSize + 1;

            string SortExpression = DataGridNews.Attributes["SortExpression"];
            string SortDirection  = DataGridNews.Attributes["SortDirection"];

            SqlDS.Tables["NewsInfo"].DefaultView.Sort = SortExpression + " " + SortDirection;

            DataGridNews.DataSource = SqlDS.Tables["NewsInfo"].DefaultView;
            DataGridNews.DataBind();
            for (int i = 0; i < DataGridNews.Items.Count; i++)
            {
                LinkButton LBNewsTitle = (LinkButton)DataGridNews.Items[i].FindControl("LinkButNewsTitle");
                LBNewsTitle.Text = Server.HtmlEncode(LBNewsTitle.Text);
                if (LBNewsTitle.Text.Trim().Length > 30)
                {
                    LBNewsTitle.Text = LBNewsTitle.Text.Trim().Substring(0, 30) + "...";
                }

                LBNewsTitle.Attributes.Add("onclick", "javascript:jscomNewOpenByFixSize('BrowNews.aspx?NewsID=" + DataGridNews.Items[i].Cells[0].Text + "','BrowNews',458,323); return false;");

                Label labCreateDate = (Label)DataGridNews.Items[i].FindControl("labCreateDate");
                labCreateDate.Text = Convert.ToDateTime(labCreateDate.Text).ToString("d");

                LinkButton LBBrowNews = (LinkButton)DataGridNews.Items[i].FindControl("LinkButBrowNews");
                LBBrowNews.Attributes.Add("onclick", "javascript:jscomNewOpenByFixSize('BrowNews.aspx?NewsID=" + DataGridNews.Items[i].Cells[0].Text + "','BrowNews',458,323); return false;");
            }
            LabelRecord.Text      = Convert.ToString(SqlDS.Tables["NewsInfo"].Rows.Count);
            LabelCountPage.Text   = Convert.ToString(DataGridNews.PageCount);
            LabelCurrentPage.Text = Convert.ToString(DataGridNews.CurrentPageIndex + 1);
            SqlConn.Dispose();
        }