|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to put an image in a GridViewthe fields at run time and create a table containing my data and then bind it to the Gridview. My cod e is shown below: DataTable dt = dataSet1.Tables.Add("Imagetable"); dt.Columns.Add(new DataColumn("File path", typeof(string))); dt.Columns.Add(new DataColumn("Image file", typeof(System.Web.UI.WebControls.Image))); // this is a loop { DataRow dr = dataSet1.Tables["Imagetable"].NewRow(); dr[0] = name.ToString(); System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image(); image.ImageUrl = dirpath + name; image.Height = 50; image.Visible = true; dr[1] = image; dataSet1.Tables["Imagetable"].Rows.A dd(dr); } DataView v = new DataView(dt); GridView1.DataSource = v; GridView1.DataBind(); My first column displays ok but the second column which is the image column does not even display a column at all or even the heading. Does anyone know what the problem is? > dt.Columns.Add(new DataColumn("Image file", Is System.Web.UI.WebControls.Image a legal datatype value? Shouldn't it be > typeof(System.Web.UI.WebControls.Image))); Byte? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassdatatypetopic.asp Ken Microsoft MVP [ASP.NET] Show quoteHide quote "Parrot" <Par***@discussions.microsoft.com> wrote in message news:C257D9AB-4272-4F88-ACC2-4BB415143DC5@microsoft.com... >I cannot get an image to display in a column of my GridView control. I >build > the fields at run time and create a table containing my data and then bind > it > to the Gridview. My cod e is shown below: > > DataTable dt = dataSet1.Tables.Add("Imagetable"); > dt.Columns.Add(new DataColumn("File path", typeof(string))); > dt.Columns.Add(new DataColumn("Image file", > typeof(System.Web.UI.WebControls.Image))); > > // this is a loop > { > > DataRow dr = dataSet1.Tables["Imagetable"].NewRow(); > > dr[0] = name.ToString(); > System.Web.UI.WebControls.Image image = new > System.Web.UI.WebControls.Image(); > image.ImageUrl = dirpath + name; > image.Height = 50; > image.Visible = true; > dr[1] = image; > dataSet1.Tables["Imagetable"].Rows.A dd(dr); > } > > DataView v = new DataView(dt); > GridView1.DataSource = v; > GridView1.DataBind(); > > My first column displays ok but the second column which is the image > column > does not even display a column at all or even the heading. Does anyone > know > what the problem is? I tried changing the datatype to byte but that resulted in a data exception.
In a nutshell I cannot get an image file to display at all if I define it dynamically in a table. I tried the approach suggested by another writer in this forum in which I created an Image file when defining the Gridview using the Smart tag editing feature. Then I assigned to the DataImageUrl Field the name of a string field which I dynamically created at run time in the same way that I created the image field that wouldn't work. By using this approach I assigned to this string field the path of the image file that I wish to display. This approach worked for some of the image files but not all of them. I could not find a pattern as to why some image files would display and some not - they all went through a loop of the file directory. I am at a loss as to what to do next. What should be a simple procedure is turning into another time burning process. I can tell you that Visual Studio 2005 has been a very time consuming and frustrating tool to work with, especially in converting existing applications from VS 2003. In retrospect I wished that I had left everything under 2003. The fact that I have to upload cs files as well as aspx files to the server was not at all intuitive to me and seems to a step backwards. VS 2005 is not ready for prime time. Show quoteHide quote "Ken Cox [Microsoft MVP]" wrote: > > dt.Columns.Add(new DataColumn("Image file", > > typeof(System.Web.UI.WebControls.Image))); > > Is System.Web.UI.WebControls.Image a legal datatype value? Shouldn't it be > Byte? > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassdatatypetopic.asp > > Ken > Microsoft MVP [ASP.NET] > > "Parrot" <Par***@discussions.microsoft.com> wrote in message > news:C257D9AB-4272-4F88-ACC2-4BB415143DC5@microsoft.com... > >I cannot get an image to display in a column of my GridView control. I > >build > > the fields at run time and create a table containing my data and then bind > > it > > to the Gridview. My cod e is shown below: > > > > DataTable dt = dataSet1.Tables.Add("Imagetable"); > > dt.Columns.Add(new DataColumn("File path", typeof(string))); > > dt.Columns.Add(new DataColumn("Image file", > > typeof(System.Web.UI.WebControls.Image))); > > > > // this is a loop > > { > > > > DataRow dr = dataSet1.Tables["Imagetable"].NewRow(); > > > > dr[0] = name.ToString(); > > System.Web.UI.WebControls.Image image = new > > System.Web.UI.WebControls.Image(); > > image.ImageUrl = dirpath + name; > > image.Height = 50; > > image.Visible = true; > > dr[1] = image; > > dataSet1.Tables["Imagetable"].Rows.A dd(dr); > > } > > > > DataView v = new DataView(dt); > > GridView1.DataSource = v; > > GridView1.DataBind(); > > > > My first column displays ok but the second column which is the image > > column > > does not even display a column at all or even the heading. Does anyone > > know > > what the problem is? > > >
Dropdown List doesn't know what's in it's list
dropdown list post back not working Max Number of Web Controls Per Page??? ObjectDataSource ControlParameters Problem with ASP.NET wizard hiding / removing steps textfield not recognized in gridview Datagrid Control in VS2005 Datagrids and User Controls Custom Templated CompositeControl/CompositeControlDesigner GridView columns don't respect width or wrap properties! |
|||||||||||||||||||||||