Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Original:
how to add text boxes data into grid view when button click add then dat will display in grid view and how to search value or find the data in gridview

Modified:
How to add data from text boxes into grid view when add button is clicked in grid view?
How to search value or find the data in gridview?
Posted
Updated 27-Jun-11 18:12pm
v2

You add them in your template for how the data is displayed. Your issue is, then need to be added before page load in order for viewstate to work.

You never search in your grid, you always search your data source.

dat is not a word.
 
Share this answer
 
Comments
Wild-Programmer 28-Jun-11 0:14am    
Good answer :) my 5+
OP is having some linguistic difficulty in expressing himself :)
[no name] 28-Jun-11 0:44am    
Good Call CG.My 5 too.
Christian is right regarding adding textbox to the datagrid. Below is code sample to help you:

<asp:datagrid id="dg" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
            <columns>
                <asp:boundcolumn datafield="id"></asp:boundcolumn>
                <asp:templatecolumn>
                    <itemtemplate>
                        <asp:textbox id="txt" runat="server" text="<%#DataBinder.Eval(Container.DataItem,"name") %>"></asp:textbox>
                    </itemtemplate>
                </asp:templatecolumn>
            </columns>
        </asp:datagrid>


To read textbox data you need to first find the control for each row. Below sample may help you:
// Loop through the datagrid rows
foreach (DataGridItem item in dg.Items)
{
    // Get textbox corresponding to the row
    TextBox a= item.FindControl("txt") as TextBox;
    if (a != null)
    {
        // Your logic to access the textbox
    }
}


This is for server side code. You can also access the grid's controls at client side (JQuery recommended).
 
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