asp.net - 无法将数据放入固定宽度的 GridView 单元格中

标签 asp.net css sql gridview

我有一个包含很长文本的列,我必须滚动到末尾才能看到它。你能帮忙把内容放在固定宽度的单元格中吗

用户界面:

 <asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="PageIndexChanging_Click" 
                style="height: 166px; width: 217px; z-index: 1; left: 16px; top: 252px; position: absolute" 
                EmptyDataText="No Records Within this time Frame"  >
                <PagerSettings LastPageText="Last"  />
            </asp:GridView>

//Code Behind:   


    private void GetData()
            {
                string fromdata =  txt_fromdate.Text;//" '2013-09-23 11:06:00.077'";
                string todate =  txt_todata.Text;//" '2013-09-23 11:28:25.163' ";
                string querstring = "select * from gt_transaction_log where LogTimeStamp between" +"'"+ fromdata +"'"+ " and " +"'"+ todate + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(querstring, conn);
                DataTable dt = new DataTable();
                GridView1.AllowPaging = true;
                if (TextBox1.Text != "" && int.Parse(TextBox1.Text) != 0)
                {
                    GridView1.PageSize = int.Parse(TextBox1.Text);
                }
                else
                { GridView1.PageSize = 10; }
                adapter.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();

            }

最佳答案

GridView 没有 Style 属性,但它有一个 CssClass 属性,您可以使用它来控制其 CSS。

在样式 block 中创建 CSS:

<style type="text/css">
        .gridViewStyle {
            height: 166px;
                width: 217px; 
                z-index: 1; 
                left: 16px; 
                top: 252px; 
                position: absolute
        }
</style>

然后在您的 GridView 中,它将如下所示:

<asp:GridView CssClass="gridViewStyle" <!-- additional GV fields here -->>
</asp:Gridview>

关于asp.net - 无法将数据放入固定宽度的 GridView 单元格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18991862/

相关文章:

CSS - 填充影响 DIV 上的背景图像

html - 如何使用多个类选择器为多个元素简化 css 规则

jquery - Target 与多个元素具有相同类名的单个元素

mysql - 用于将列值设置为与下一行的列值相同的 SQL

php - MySQL 链接表;一些最后的问题

c# - ASP.NET 中的 Microsoft Search Server 或 Microsoft Search Service

c# - Visual Studio 2012 给出了荒谬的错误

SQL - 使用正则表达式的动态查找

c# - 在 .Where() 中使用 .SingleOrDefault() 将引发以下异常 :- System. NotSupportedException 未被用户代码处理

asp.net - 如何并排放置复选框?