how to transfer the values of textboxes from one form to another form in datagridviw control without using database
-
i have two forms, in one form i have three textboxes and in another form i have one datagrid view control, i want that the data i entered in textboxes will shown in datagridview control after i click on add button all the records will store in it may it is n number of record all n number of record will be shown in datagridview control but without creating database.. Is there any mechanism how to do this..????
-
i have two forms, in one form i have three textboxes and in another form i have one datagrid view control, i want that the data i entered in textboxes will shown in datagridview control after i click on add button all the records will store in it may it is n number of record all n number of record will be shown in datagridview control but without creating database.. Is there any mechanism how to do this..????
This is so simple to do. Create a class which contains 3 properties for all three text boxes. Say for example here is the sample code
public class Form1Class
{
public string TextBox1Value { get; set; }public string TextBox2Value { get; set; }
public string TextBox3Value { get; set; }
}
Now say for example you have a button named Button1 and on the click even, you need to open Form2 and bind the textbox values to datagridview. For this, first you have to create an object of Form1Class which will take these three textbox values into my object (here it is Form1Class). Once you created an object, you need to pass the object to Form2 Here, you have to think about data passing mechanism from one form to another form (Form1 to Form2). There are many methods that we can pass data from one form to another. 1. You can use sessions, querystring etc... For detailed view of how to pass data from one form to another form in asp.net , have a look at below links MSDN article or this article also gives you an idea Null Skull link Once you pass the data from From1 to Form2 and the receiver side (i.e Form2) you need to receive the data and bind it to the datagridview. As you are passing a single object from Form1 to Form2 and you need to see how to bind an object to datagridivew. here is the stackoverflow answer on how to bind an object or a list of object(s) to a datagridview. Stack Overflow answer Once you are bind the data to a datagrid view, you can able to see the data that you enter in textbox(es) in Form1. Try this and let us know, if it is working or else facing any issues. Happy coding :)
Regards, Ganesh
-
i have two forms, in one form i have three textboxes and in another form i have one datagrid view control, i want that the data i entered in textboxes will shown in datagridview control after i click on add button all the records will store in it may it is n number of record all n number of record will be shown in datagridview control but without creating database.. Is there any mechanism how to do this..????
In this case what you can do is create a custom data table in the form, having three columns as the three text box, Once you have this structure in place you can create a data row and append it to the table and set the datatable as the data source of the gridview. let me know if you have any question.