[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to populate a datagrid with textboxes

Posted on 2003-11-28
5
Medium Priority
?
622 Views
Last Modified: 2008-02-01
It it possible to display column information in a datagrid using just textboxes instead of text?  If so, I would like an example on how this is done.
0
Comment
Question by:Thrakrath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:NaliniP
ID: 9841484
Thrakrath , here is the example.

First you need to bind the datasource to the datagrid. Then you have to change the code so that it will show the text boxes instead of text. look at this..

Imports System.Data.Oledb

Dim Cn as new oledbconnection
dim cmd as new oledbcommand
dim adp as new oledbdataadaptor
dim dset as new dataset
Dim Ctr as integer
dim col1 as string

cn.connectionstring="PROVIDER=MSDAORA.1;USER ID=SCOTT;PASSWORD=TIGER"
cmd.connection=cn
cmd.commandtext="select * from emp"
cmd.commandtype=Text
adp.selectcommand=cmd
adp.fill(dset)

datagrid1.datasource=dset
datagrid1.databind()

col1 = dset.tables(0).columns(0).caption 'Field Name of the First Column

for ctr=0 to datagrid1.items.count-1
   datagrid1.items(ctr).item(0).controls.add(new Literalcontrol("<INPUT TYPE=TEXT NAME=" & col1 & ctr & " VALUE=" & datagrid1.items(ctr).item(0).text & ">"))
......
......
......you can repeat for all the cell in the grid.
next

***************************
by doing the above way, you will get what you wanted. Hope this may help you.........cheers

Nalini
0
 

Author Comment

by:Thrakrath
ID: 9841756
Thanks NaliniP for your suggestion. Unfortunally I use C# so do you think you have the above example written in C# code.

If not, mabye you could help me out with the following lines of code.

These lines returns the following error during compile time:

#1
col1 = dset.Tables(0).columns(0).caption;
//'System.Data.DataSet.Tables' denotes a 'property' where a 'method' was expected

#2
for (int i = 0; i < RoutePortCalls.Items.count-1; i++)
//'System.Web.UI.WebControls.DataGridItemCollection' does not contain a definition for 'count'

#3
RoutePortCalls.items(i).item(0).controls.add(new Literalcontrol("<INPUT TYPE=TEXT NAME=" & col1 & i & " VALUE=" & datagrid1.items(i).item(0).text & ">"));
//The type or namespace name 'Literalcontrol' could not be found (are you missing a using directive or an assembly reference?)
0
 
LVL 2

Accepted Solution

by:
NaliniP earned 375 total points
ID: 9841770
you need to declare the datagrid first. I mean you have to place a datagrid control on your web form. then the above code works. there is nothing difference in the code whether it is vb.net or c#.net. only the thing is ';' and case sensitivity. so look at that..if problem come again..

Nalini
0
 

Author Comment

by:Thrakrath
ID: 9841805
I already have a datagrid that is bound to a datasource. I made a few changes to your example and now I only get one error.

In line:

RoutePortCalls.Items[i].Item[0].controls.add(new LiteralControl("<INPUT TYPE=TEXT NAME=" + col1 + i + " VALUE=" + RoutePortCalls.Items[i].Item[0].text + ">"));

I get the following error:

'System.Web.UI.WebControls.DataGridItem' does not contain a definition for 'Item'
0
 

Author Comment

by:Thrakrath
ID: 9841827
One other thing worth mentioning. I dont use a dataset when binding data to my datagrid. I'm using a method.

The code is:

private void Page_Load(object sender, System.EventArgs e)
{
     RoutePortCalls.DataSource = CreateDataSourceRoutePortCalls();
     RoutePortCalls.DataBind();
}

private ICollection CreateDataSourceRoutePortCalls()
{
     DataTable dt = new DataTable();
     DataView dv = new DataView(dt);
     DataRow dr;

     try
     {
          dt.Columns.Add(new DataColumn("Id"));
          dt.Columns.Add(new DataColumn("PortNameDataField"));
          dt.Columns.Add(new DataColumn("TerminalDataField"));
          dt.Columns.Add(new DataColumn("EndDataField"));
          dt.Columns.Add(new DataColumn("StartDataField"));

          dr = dt.NewRow();
          dr["PortNameDataField"] = "1";
          dr["PortNameDataField"] = "PortName One";
          dr["TerminalDataField"] = "Terminal One";
          dr["EndDataField"] = "2003-11-23";
          dr["StartDataField"] = "2003-12-10";
          dt.Rows.Add(dr);

          dr = dt.NewRow();
          dr["PortNameDataField"] = "2";
          dr["PortNameDataField"] = "PortName Two";
          dr["TerminalDataField"] = "Terminal Two";
          dr["EndDataField"] = "2003-12-01";
          dr["StartDataField"] = "2003-12-19";
          dt.Rows.Add(dr);
     }
     catch (Exception ex)
     {
          Response.Write (ex);
     }

     return dv;
}
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question