Click here to Skip to main content
16,015,072 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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. ...

XML
<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>
Posted
Comments
thatraja 26-Feb-11 13:50pm    
Include your code of code-behind here too.

GridView is not rendered until you set its dataSource property and call dataBind().

Try following
C#
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];



Change the Control name in your GridView
<ItemTemplate>
        <asp:TextBox Id="dregreName"     runat="server"></asp:TextBox>
   </ItemTemplate>
 
Share this answer
 
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[] { "", "", "" };


Hope u could use this.

--Pankaj
 
Share this answer
 
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.
 
Share this answer
 
v2
solution not working ... Please post if you have any other solution to this problem ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900