Mokshasri

Mokshasri

  • NA
  • 31
  • 0

Urgent: Image is not displayed and paging problem in Gridview ASP.NET 3.5

Dec 10 2009 6:18 AM
Hi Experts!
              Can any one help me to over come the following problem?
I am facing 2 problems while working with ASP.NET 3.5 GridView control viz., 1) Paging is displayed, but once clicked on page2, it goes but then it gets disabled (not able to click again and not able to move to page1 Clicking on page is not responding and it is remaining in page 2 only.

                  2) I have tried adding a new column of type Imagefield and tried, but now this field shows a text "Image" and not image itself.

           I have the following code: .aspx page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:GridView ID="gv_displaydata" runat="server" BorderColor="#CC9966"
            BorderStyle="None" BorderWidth="1px"
               BackColor="White" CellPadding="4" Width="100%"
            AutoGenerateColumns="False" Height="129px"
            AllowPaging="True"
            onpageindexchanged="gv_displaydata_PageIndexChanged" onpageindexchanging="gv_displaydata_PageIndexChanging"           
            >
            <Columns>
                <asp:BoundField FooterText="AUTHOR ID" HeaderText="ID" DataField="id">
                    <ControlStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" Font-Size="Medium" Font-Underline="True" ForeColor="#FFFFCC" />
                    <FooterStyle BackColor="#FFFFCC" Font-Bold="True" ForeColor="#993300" />
                    <HeaderStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" ForeColor="#FFFFCC" />
                </asp:BoundField>
                <asp:BoundField HeaderText="AUTHOR" DataField="author">
                <ControlStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" Font-Size="Medium" Font-Underline="True" ForeColor="#FFFFCC" />
                    <FooterStyle BackColor="#FFFFCC" Font-Bold="True" ForeColor="#993300" />
                    <HeaderStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" ForeColor="#FFFFCC" />
                </asp:BoundField>
                <asp:BoundField HeaderText="DESCRIPTION" DataField="description">
                <ControlStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" Font-Size="Medium" Font-Underline="True" ForeColor="#FFFFCC" />
                    <FooterStyle BackColor="#FFFFCC" Font-Bold="True" ForeColor="#993300" />
                    <HeaderStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" ForeColor="#FFFFCC" />
                </asp:BoundField>
                <asp:ImageField DataImageUrlField="photo" HeaderText="Photo">
                <ControlStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" Font-Size="Medium" Font-Underline="True" ForeColor="#FFFFCC" />
                    <FooterStyle BackColor="#FFFFCC" Font-Bold="True" ForeColor="#993300" />
                    <HeaderStyle BackColor="#993300" BorderColor="#FFCC00" BorderStyle="Inset"
                        Font-Bold="True" ForeColor="#FFFFCC" />
                </asp:ImageField>
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1"
      TypeName="ImageDAL"
      SelectMethod ="GetAuthor"
      runat="server">
    </asp:ObjectDataSource>

        <P>
            <asp:Label id="NotificationLabel" runat="server" Visible="False"></asp:Label>
           
        </P>
    </div>
    </form>
</body>
</html>

            Code in the aspx.cs file:
namespace diplaydata
{

    public partial class displaytabledata : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        private DataTable getTable()
        {


            //OracleDataAdapter adap = new OracleDataAdapter("select t.id, t.author, t.description from smstestblob t", "Data Source=PROWESS;User ID=DBA_PST;Password=PST;");
            OracleDataAdapter adap = new OracleDataAdapter("select t.id, t.author, t.description, t.photo from smstestblob t", "Data Source=PROWESS;User ID=DBA_PST;Password=PST;");
            //DataSet set = new DataSet();
           
            DataTable dt = new DataTable();
            adap.Fill(dt);
           
            Response.Write("Rows In Data Table " + dt.Rows.Count.ToString());
            return dt;


        }


        protected void bind()
        {
            DataTable dr = getTable();
           
            gv_displaydata.DataSource = dr;
           
            gv_displaydata.DataBind();
            gv_displaydata.Visible = true;
            gv_displaydata.Font.Bold = true;
            //gv_displaydata.AllowPaging;
        }

        protected void gv_displaydata_PageIndexChanged(object sender, EventArgs e)
        {
            gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
            bind();
        }


       /*protected void gv_displaydata_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
            bind();
        }

        protected void gv_displaydata_SelectedIndexChanged(object sender, EventArgs e)
        {
            gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
            bind();
        }*/
        protected void gv_displaydata_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gv_displaydata.PageIndex = gv_displaydata.PageIndex + 1;
            bind();
        }


}

}


Thanks in advance for your help again.



Regards


Answers (1)