asp.netmicrosoft-expression-web

Page load is returning into blank page


What's wrong in my page? When I'm trying to load my page. It returns into a Blank Page. What's wrong?

please review my code, it returns null or a blank page in browser.

it shows nothing even errors. Just when i try to load it. A full all blank white displays on my browser.

Here's my code:

<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>

<script runat="server" type="css">

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        bind();
    }
}
protected void bind()
{
    PendingRecordsGridview.DataSourceID = "";
    PendingRecordsGridview.DataSource = sd1;
    PendingRecordsGridview.DataBind();
 }
protected void PendingRecordsGridview_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "accept")
    {
        Session["id"] = e.CommandArgument.ToString();
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            con.Open();
            SqlCommand cmd1 = new SqlCommand("INSERT INTO tb2 (id, name) SELECT id, name FROM tb1 where id='"+Session["id"].ToString()+"'", con);
            SqlCommand cmd2 = new SqlCommand("delete from tb1 where id='"+Session["id"].ToString()+"'", con);
            cmd1.ExecuteNonQuery();
            cmd2.ExecuteNonQuery();
            bind();
    }
}
</script>
<form id="form1" runat="server">
<asp:GridView ID="PendingRecordsGridview" runat="server" AutoGenerateColumns="False" DataKeyNames="id" onrowcommand="PendingRecordsGridview_RowCommand" DataSourceID="sd1">
        <Columns>
            <asp:templatefield HeaderText="Accept">
                <ItemTemplate>
                    <asp:Button CommandArgument='<%# Bind("id") %>' ID="Button1" runat="server" CausesValidation="false" CommandName="accept" Text="Accept" />
                </ItemTemplate>
            </asp:templatefield>
            <asp:templatefield HeaderText="name" SortExpression="name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("name") %>'>
                    </asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("name") %>'>
                    </asp:Label>
                </ItemTemplate>
            </asp:templatefield>
            <asp:templatefield HeaderText="id" SortExpression="id">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'>
                    </asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("id") %>'>
                    </asp:Label>
                </ItemTemplate>
            </asp:templatefield>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="sd1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM [tb1]">
</asp:SqlDataSource>
</form>  

Solution

  • In your bind method you are clearing the DataSourceID of the Grid and setting the DataSource property.

    The DataSource property expects actual data.

    You probably should change this to.

     PendingRecordsGridview.DataSourceID = "sd1";
        PendingRecordsGridview.DataBind();
    

    Or comment out the entire method as it doesn't really do anything useful anyway.