在网格视图中看不到数据 [英] Unable to see data in the grid view

查看:68
本文介绍了在网格视图中看不到数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了我想使用gridview从用户那里接受数据的代码.现在,我无法在页面加载事件中看到gridview. ...

I write the code where I want to accept the data from user using gridview .. now m unable to see the the gridview on the page load event. ...

<asp:GridView ID="GridView1" runat="server" CellPadding="4"

                    EnableModelValidation="True" ForeColor="#333333" GridLines="Vertical"

                    AutoGenerateColumns="False" >
                    <EditRowStyle BackColor="#2461BF" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EFF3FB" />
                    <SelectedRowStyle Font-Bold ="true" ForeColor ="#333333" BackColor="#D1DDF1" />

                    <AlternatingRowStyle BackColor="White" />



                    <Columns>

                        <asp:TemplateField HeaderText="Degree Level">
                            <ItemTemplate>
                                <asp:DropDownList ID="degree" runat="server" AutoPostBack="True">
                                    <asp:ListItem>Select..</asp:ListItem>
                                    <asp:ListItem>SSC</asp:ListItem>
                                    <asp:ListItem>HSC</asp:ListItem>
                                    <asp:ListItem>Diploma</asp:ListItem>
                                    <asp:ListItem>Graduation</asp:ListItem>
                                    <asp:ListItem>Post Graduation</asp:ListItem>
                                    <asp:ListItem>PHD</asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Degree Name">
                            <ItemTemplate>
                                <asp:TextBox Id="degree" runat ="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Passing Year">
                            <ItemTemplate>
                                <asp:TextBox ID="passingyear" runat="server" MaxLength ="4"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Percentage">
                            <ItemTemplate>
                                <asp:TextBox ID="percentage" runat="server" MaxLength ="2"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                       </Columns>
                </asp:GridView>

推荐答案

GridView在您设置其dataSource 属性并调用dataBind()之前不会呈现.
尝试关注
GridView is not rendered until you set its dataSource property and call dataBind().

Try following
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int[] i = new int[10];
            GridView1.DataSource = i;
            GridView1.DataBind();
        }

    }




您可以更改数组的长度以获取更多行.




You may change the Length of the Array to get more rows.

int[] i = new int[100];




在GridView中更改控件名称




Change the Control name in your GridView

<ItemTemplate>
        <asp:TextBox Id="dregreName"     runat="server"></asp:TextBox>
   </ItemTemplate>


如果没有为网格提供数据源,则看不到该网格,因为网格用于显示某些绑定数据
我在页面加载时使用了以下行以在网格中显示3行
you can not see this grid if you did not provide datasource to the grid because grid is used to show some bound data
i used following line at page load to show 3 lines in grid
GridView1.DataSource = new string[] { "", "", "" };



希望你可以使用它.

--Pankaj



Hope u could use this.

--Pankaj


我认为以下链接将为您提供帮助:

如何在asp.net中使用GridView
到GridView的数据绑定
GridView控件详细信息

如果我误解了您的问题,请随时纠正我.希望以上信息对您有所帮助.如果您还有其他顾虑,请告诉我.

如果这对您真的很有帮助,请不要忘记投票并接受答案.
I think the following links will help you out:

how to use GridView in asp.net
DataBinding to GridView
GridView Control Detail

If i misunderstand your question, please feel free to correct me.I hope the above information will be helpful. If you have more concerns, please let me know.

If this would be really helpful to you then don''t forgot to Vote and Make Answer as Accepted.


这篇关于在网格视图中看不到数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆