locked
Gridview is not getting display in MultiView1 RRS feed

  • Question

  • User-367318540 posted

    my gridview is not getting display please guide,

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Opnsorce@.aspx.cs" Inherits="WebApplication21.View.Admin.Opnsorce_" %>
    
    
    
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"  
    type="text/javascript"></script>   
    <!--include jQuery Validation Plugin-->  
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"  
    type="text/javascript"></script>  
        <link href="../../css/bootstrap-theme.css" rel="stylesheet" />
        <link href="../../css/bootstrap-theme.min.css" rel="stylesheet" />
        <link href="../../css/bootstrap.css" rel="stylesheet" />
        <link href="../../css/bootstrap.min.css" rel="stylesheet" />
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
    
    
         <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    body {
        font-family: "Lato", sans-serif;
    }
    
    .sidenav {
        height: 100%;
        width: 0;
        ;
        z-index: 1;
        top: 0;
        left: 0;
        background-color: #111;
        overflow-x: hidden;
        transition: 0.5s;
        padding-top: 60px;
    }
    
    .sidenav a {
        padding: 8px 8px 8px 32px;
        text-decoration: none;
        font-size: 25px;
        color: #818181;
        display: block;
        transition: 0.3s;
    }
    
    .sidenav a:hover {
        color: #f1f1f1;
    }
    
    .sidenav .closebtn {
        ;
        top: 0;
        right: 25px;
        font-size: 36px;
        margin-left: 50px;
    }
    
    @media screen and (max-height: 450px) {
      .sidenav {padding-top: 15px;}
      .sidenav a {font-size: 18px;}
    }
    </style>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <div id="mySidenav" class="sidenav">
      <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Post An Ad</asp:LinkButton>
     <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">View or Manage Ads</asp:LinkButton>
     
     
      
    </div>
    
          <h3 Style="float:right"> <asp:Label ID="Label1" runat="server" Text="Label" ForeColor="#33CC33" ></asp:Label></h3>
           <h4 Style="float:right">  <asp:Button ID="Button2" runat="server" Text="LogOut" OnClick="Button2_Click" BackColor="#CC0000" ForeColor="White" Width="104px" /> </h4>
    <h2 style align="center">Admin Panal </h2>
    <p></p>
    <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>
            <asp:MultiView ID="MultiView1" runat="server">
                <asp:View ID="View1" runat="server" ViewStateMode="Enabled">
                    <div style=";width:500px; height:700px;margin:0 auto;">
                        <h1> Post a New AD</h1>
    
                         <table class="auto-style1 table table-bordered table-responsive progress-striped">
                <tr>
                    <td>Select Category</td>
                    <td><asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="130px" DataSourceID="SqlDataSource1" DataTextField="cat_name" DataValueField="cat_id"></asp:DropDownList></td>
                    
                   
                </tr>
                <tr>
                    <td>Product Name</td>
                    <td>
                   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td>
                     
                </tr>
             
                <tr>
                    <td>Date</td>
                    <td>
                   <asp:TextBox ID="TextBox2" runat="server" ReadOnly="true"></asp:TextBox> </td>
                     
                </tr>
    
                <tr>
                    <td>Product Price</td>
                    <td>
                   <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td>
                     
                </tr>
    
     <tr>
                    <td>Product Image</td>
                    <td>
                   
                         <asp:FileUpload ID="FileUpload1" runat="server" />
                         <asp:GridView ID="GridView2" runat="server"  AutoGenerateColumns="false"  ShowHeader="false" Width="249px">
                             <Columns>
                                 <asp:BoundField DataField="_ID" HeaderText="ID" Visible="false" />
                                 <asp:TemplateField HeaderText="Pics">
                                     <ItemTemplate>
                                         <asp:FileUpload ID="FileUpload2" runat="server" />
                                     </ItemTemplate>
                                 </asp:TemplateField>
                             </Columns>
                         </asp:GridView>
                         <br />
                         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ecom %>" SelectCommand="SELECT * FROM [tbl_product_category]"></asp:SqlDataSource>
                   
                         </td>
         
                </tr>
    
                             <tr>
                                 
                                 <td> &nbsp;</td>
                                 <td>
                                   
                                 </td>
                             </tr>
    
    
                             <tr>
                                 <td>
                                     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Post" />
                                 </td>
                                 <td>
                                     <asp:Label ID="Label2" runat="server" ForeColor="Red" Text=""></asp:Label>
                                     <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">View this ad</asp:LinkButton>
                                 </td>
                             </tr>
    
    
            </table>
    
    
    
    
    
    
            </div>
    
                </asp:View>
    
                <asp:View ID="View2" runat="server">
    
                    <div style="width:500px; height:700px;margin:0 auto;">
    
                        <h1 style="text-align:center">&nbsp;</h1>
    
    
    
            </div>
    
                </asp:View>
                
    
            </asp:MultiView>
            
    
    
        </div>
        </form>
    
    
        
    <script>
    function openNav() {
        document.getElementById("mySidenav").style.width = "250px";
    }
    
    function closeNav() {
        document.getElementById("mySidenav").style.width = "0";
    }
    </script>
    </body>
    </html>
    
    



    Saturday, October 19, 2019 7:42 AM

Answers

  • User409696431 posted

    Your code does not show any assignment of a datasource to the GridView.  If you do it in code behind, show us the code.  If you intended to do it declaratively, add the datasource assignment to the GridView line.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 20, 2019 9:23 PM
  • User288213138 posted

    Hi akhterr,

    my gridview is not getting display please guide,

    Can you show me how do you bind data?

    This is my test code, it works fine.

    <asp:MultiView ID="MultiView1" runat="server">
                    <asp:View ID="View1" runat="server" ViewStateMode="Enabled">
                        <div style="width: 500px; height: 700px; margin: 0 auto;">
                            <h1>Post a New AD</h1>
                            <table class="auto-style1 table table-bordered table-responsive progress-striped">
                                <tr>
                                    <td>Select Category</td>
                                    <td>
                                        <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="130px"></asp:DropDownList></td>
                                </tr>
                                <tr>
                                    <td>Product Name</td>
                                    <td>
                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Date</td>
                                    <td>
                                        <asp:TextBox ID="TextBox2" runat="server" ReadOnly="true"></asp:TextBox>
                                    </td>
                                </tr>
    
                                <tr>
                                    <td>Product Price</td>
                                    <td>
                                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                                    </td>
    
                                </tr>
    
                                <tr>
                                    <td>Product Image</td>
                                    <td>
    
                                        <asp:FileUpload ID="FileUpload1" runat="server" />
                                        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" ShowHeader="false" Width="249px">
                                            <Columns>
                                                <asp:BoundField DataField="_ID" HeaderText="ID" Visible="false" />
                                                <asp:TemplateField HeaderText="Pics">
                                                    <ItemTemplate>
                                                        This is Gridview fileupload:<asp:FileUpload ID="FileUpload2" runat="server" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                        </asp:GridView>
                                        <br />
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td></td>
                                </tr>
    
                                <tr>
                                    <td>
                                        <asp:Button ID="Button1" runat="server" Text="Post" />
                                    </td>
                                    <td>
                                        <asp:Label ID="Label2" runat="server" ForeColor="Red" Text=""></asp:Label>
                                        <asp:LinkButton ID="LinkButton3" runat="server">View this ad</asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </asp:View>
    
                    <asp:View ID="View2" runat="server">
                        <div style="width: 500px; height: 700px; margin: 0 auto;">
                            <h1 style="text-align: center">&nbsp;</h1>
                        </div>
                    </asp:View>
                </asp:MultiView>
    
    
                 if (!IsPostBack)
                {
                    MultiView1.ActiveViewIndex = 0;
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("_ID"), new DataColumn("Name"), new DataColumn("Country") });
                    dt.Rows.Add(1, "name1", "country1");
                    dt.Rows.Add(2, "name2", "country2");
                    dt.Rows.Add(3, "name3", "country3");
                    GridView2.DataSource = dt;
                    GridView2.DataBind();
                }

    The result:

    Best regards,

    sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 21, 2019 7:49 AM

All replies

  • User409696431 posted

    Your code does not show any assignment of a datasource to the GridView.  If you do it in code behind, show us the code.  If you intended to do it declaratively, add the datasource assignment to the GridView line.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 20, 2019 9:23 PM
  • User288213138 posted

    Hi akhterr,

    my gridview is not getting display please guide,

    Can you show me how do you bind data?

    This is my test code, it works fine.

    <asp:MultiView ID="MultiView1" runat="server">
                    <asp:View ID="View1" runat="server" ViewStateMode="Enabled">
                        <div style="width: 500px; height: 700px; margin: 0 auto;">
                            <h1>Post a New AD</h1>
                            <table class="auto-style1 table table-bordered table-responsive progress-striped">
                                <tr>
                                    <td>Select Category</td>
                                    <td>
                                        <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="130px"></asp:DropDownList></td>
                                </tr>
                                <tr>
                                    <td>Product Name</td>
                                    <td>
                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Date</td>
                                    <td>
                                        <asp:TextBox ID="TextBox2" runat="server" ReadOnly="true"></asp:TextBox>
                                    </td>
                                </tr>
    
                                <tr>
                                    <td>Product Price</td>
                                    <td>
                                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                                    </td>
    
                                </tr>
    
                                <tr>
                                    <td>Product Image</td>
                                    <td>
    
                                        <asp:FileUpload ID="FileUpload1" runat="server" />
                                        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" ShowHeader="false" Width="249px">
                                            <Columns>
                                                <asp:BoundField DataField="_ID" HeaderText="ID" Visible="false" />
                                                <asp:TemplateField HeaderText="Pics">
                                                    <ItemTemplate>
                                                        This is Gridview fileupload:<asp:FileUpload ID="FileUpload2" runat="server" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                        </asp:GridView>
                                        <br />
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td></td>
                                </tr>
    
                                <tr>
                                    <td>
                                        <asp:Button ID="Button1" runat="server" Text="Post" />
                                    </td>
                                    <td>
                                        <asp:Label ID="Label2" runat="server" ForeColor="Red" Text=""></asp:Label>
                                        <asp:LinkButton ID="LinkButton3" runat="server">View this ad</asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </asp:View>
    
                    <asp:View ID="View2" runat="server">
                        <div style="width: 500px; height: 700px; margin: 0 auto;">
                            <h1 style="text-align: center">&nbsp;</h1>
                        </div>
                    </asp:View>
                </asp:MultiView>
    
    
                 if (!IsPostBack)
                {
                    MultiView1.ActiveViewIndex = 0;
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("_ID"), new DataColumn("Name"), new DataColumn("Country") });
                    dt.Rows.Add(1, "name1", "country1");
                    dt.Rows.Add(2, "name2", "country2");
                    dt.Rows.Add(3, "name3", "country3");
                    GridView2.DataSource = dt;
                    GridView2.DataBind();
                }

    The result:

    Best regards,

    sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 21, 2019 7:49 AM