无法将数据放入具有固定宽度的GridView单元格中

时间:2013-09-24 20:54:36

标签: asp.net css sql gridview

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

UI:

 <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();

            }

2 个答案:

答案 0 :(得分:0)

GridView没有Style属性,但它有一个CssClass属性可用于控制其CSS。

在样式块中创建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>

答案 1 :(得分:0)

您可以使用CSS:

.Grid{
height: 166px; width: 217px; z-index: 1; left: 16px; top: 252px; position: absolute
}
.Grid tr td{
   Width:100px;
}

  <asp:GridView ID="GridView1" runat="server" CssClass="Grid" OnPageIndexChanging="PageIndexChanging_Click" EmptyDataText="No Records Within this time Frame"></asp:GridView>

OR

  <asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="PageIndexChanging_Click" 
                style="height: 166px; width: 217px; z-index: 1; left: 16px; top: 252px; position: absolute" AutoGenerateColumns="false"
                EmptyDataText="No Records Within this time Frame"  >
                    <Columns>
                        <asp:TemplateField HeaderText="Your column Name">
                            <ItemTemplate>
                                <%#Eval("EmployeeName") %>
                            </ItemTemplate>
                            <ItemStyle Width="50px" />


                        </asp:TemplateField>
                        .
                        .
                        .
                        .
                        Template fields for all columns of your datatable
                    </Columns>       
                <PagerSettings LastPageText="Last"  />
            </asp:GridView>