Solved

gridview is blank

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now