Solved

gridview is blank

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

759 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