Solved

gridview is blank

Posted on 2014-12-22
3
168 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
[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 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

622 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