Solved

gridview is blank

Posted on 2014-12-22
3
160 Views
Last Modified: 2014-12-26
I create a datatable with 0 in the cells, table creates just fine.
gridview shows up just fine
but the datatable numbers are blank in the gridview
can anyone see what I forgot?

gary

 Function createtablevendor() As DataTable
        Dim vendortable1 As New DataTable
        ' Create 16 typed columns in the DataTable.
        vendortable1.Columns.Add("Vendor_Id", GetType(Integer)) '1
        vendortable1.Columns.Add("type", GetType(String)) '2
        vendortable1.Columns.Add("Name", GetType(String)) '3
        vendortable1.Columns.Add("Address", GetType(Integer)) '4
        vendortable1.Columns.Add("town", GetType(String)) '5
        vendortable1.Columns.Add("state", GetType(String)) '6
        vendortable1.Columns.Add("zip", GetType(String)) '7
        vendortable1.Columns.Add("fax", GetType(String)) '8
        vendortable1.Columns.Add("Phone", GetType(String)) '9
        vendortable1.Columns.Add("Cell", GetType(String)) '10
        vendortable1.Columns.Add("extension", GetType(String)) '11
        vendortable1.Columns.Add("Tin", GetType(String)) '12
        vendortable1.Columns.Add("Soc_Sec", GetType(String)) '13
        vendortable1.Columns.Add("Email", GetType(Integer)) '14
        vendortable1.Columns.Add("Obsolete", GetType(String)) '15
        vendortable1.Columns.Add("Comment", GetType(String)) '16
       
        Return vendortable1
    End Function

    vendortable = createtablevendor()
                    Dst.Tables.Add(vendortable)
                    For i = 1 To 10
                        Dst.Tables("table1").Rows.Add(i, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", " ")
                        '                             1   2    3    4    5    6    7    8    9    10   11   12   13   14   15    
                    Next
                    vendortable.DefaultView.Sort = "Vendor_Id ASC"
                    gvvendorname.DataSource = Dst.Tables("table1")
                    gvvendorname.Visible = True
                    gvvendorname.DataBind()

grid shows up with all of the correct headers but the datatable does not bind to it.

 <asp:gridview id="gvvendorname"  
       autogeneratecolumns="False"
        autogenerateeditbutton="false"  
        visible = "false"              
        runat="server">  
        <columns>    
         <asp:TemplateField HeaderText="Vendor_ID">        
               <ItemTemplate>          
                  <asp:TextBox ID="tbVendor_VendorId" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>          
           <asp:TemplateField HeaderText="Vendor_Name">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxVendor_name" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_address">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_address" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
                 <asp:TemplateField HeaderText="vendor_town">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_town" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>  
               
            <asp:TemplateField HeaderText="vendor_state">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_state" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_zip">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_zip" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_fax">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_fax" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_phone">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_phone" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_cell">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_cell" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_extension">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_extension" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_tin">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_tin" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_soc_sec">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_soc_sec" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="vendor_email">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxvendor_email" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Vendor_Obsolete" ItemStyle-Width="50px">
            <ItemTemplate>
                <asp:DropDownList ID="dplvendorobsolete" runat="server" >
                <asp:ListItem Selected="True"
                        Value="0">Select</asp:ListItem>
                    <asp:ListItem>YES</asp:ListItem>
                    <asp:ListItem>NO</asp:ListItem>
                </asp:DropDownList>    
                </ItemTemplate>
        </asp:TemplateField>            
          <asp:TemplateField HeaderText="Comment">        
               <ItemTemplate>          
                  <asp:TextBox ID="TextBoxfromVendor_comment" runat="server"  ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
         </columns>
      </asp:gridview>
0
Comment
Question by:javagair
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40514009
You have not assigned each data column to the controls in the grid. This is usually done using the Eval or Bind function:
<asp:TextBox ID="TextBoxfromVendor_comment" runat="server"  ><%# Eval("Comment") %></asp:TextBox>

Open in new window

0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 40515337
It looks like you are relying on the datatable to be named "table1", this is not a good practice. You should explicitly name the table (vendortable.tablename = "table1") or reference by its index if you can rely on the position: Dst.Tables(0)

I would also recommend explicitly building the datarow before adding to the table.  It's more readable and easier to adjust as the number of columns or order changes.
dim newrow as datarow
newrow=Dst.Tables(0).newrow
newrow.item("Vendor_Id")=i
newrow.item("type")="0"
Dst.Tables(0).rows.add(newrow)
0
 

Author Closing Comment

by:javagair
ID: 40518980
don't know what I was thinking all of the rest of the web page has binding in it, totally spaced it.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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