Solved

gridview is blank

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

Accepted Solution

by:
Shaun Kline earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

10 Experts available now in Live!

Get 1:1 Help Now