Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
HI i am lakshmana rao, I have 3 text boxes and 1submit button in my page, when i click the submit button the values entered in the text boxes are displayed in the grid view,this is done with out using any ado concepts just like dataset& data table etc..,
By directly the values in the textboxes are bid to the gridview.

Please any one suggest me the solution...
thanking you...
Posted
Comments
Reza Ahmadi 12-Apr-12 7:15am    
What is your problem exactly. It seems every thing is fine??

The GridView needs to be bound to some type of datasource; a datatable, list, or any enumerable object. Take the values from the textboxes, place them in a list and bind to the gridview.
 
Share this answer
 
Comments
lakshmanarao.vemula 12-Apr-12 7:58am    
Can you give me the code for list view.
[no name] 12-Apr-12 8:29am    
Create a list, add the textbox values, bind to grid. What are you having difficulty with?
Hi ,
try this
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        if (GridView2.Rows.Count == 0)
        {
            dt = MakeTable();
            
        }
        else
        {
            dt =(DataTable) ViewState["dt"];
        }   
        DataRow dr = dt.NewRow();
        dr[0] = TextBox2.Text;
        dr[1] = TextBox3.Text;
        dr[2] = TextBox4.Text;
        dt.Rows.Add(dr);
        GridView2.DataSource = null;
        GridView2.DataSource = dt;
        GridView2.DataBind();
        ViewState.Add("dt", dt);
    }
    DataTable MakeTable()
    {
        DataTable Mydt = new DataTable();
        DataColumn col1 = new DataColumn("col");
        col1.DataType = System.Type.GetType("System.String");
        Mydt.Columns.Add(col1);

        DataColumn col2 = new DataColumn("col2");
        col1.DataType = System.Type.GetType("System.String");
        Mydt.Columns.Add(col2);


        DataColumn col3 = new DataColumn("col3");
        col1.DataType = System.Type.GetType("System.String");
        Mydt.Columns.Add(col3);
        return Mydt;
    }


OR

C#
protected void Button2_Click(object sender, EventArgs e)
{
     string[] xx = new string[3];
    xx[0] = TextBox2.Text;
    xx[1] = TextBox3.Text;
    xx[2] = TextBox4.Text;
    GridView2.DataSource= xx.ToList();
    GridView2.DataBind();

}


XML
<div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>

Best Regards
M.Mitwalli
 
Share this answer
 
v2

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