I have a dataset 'headlines' that contains single DataTable having news headlines and mage information.
Each news may have associated image with it or null if no mage exists for a new.
The dataset has only one DataTable & this DataTable will look like as seen below. Pretty simple.
news_id news_datereleased news_source news_imageurl
------- ------------------ ------------ --------------
2 12-29-03 10:20 AP
http://../ap_image1.jpg
5 12-29-03 09:30 Reuters NULL
9 12-28-03 11:30 AFP
http://../afp_image2.jpg
8 12-27-03 12:23 BBC NULL
5 12-28-03 11:30 CNN
http://../cnn_image2.jpg
7 12-27-03 12:23 AP
http://../ap_image2.jpg
Now I have a datagrid which is bound to above table. This grid has an image object
and I want to set it's imageUrl property to above 'news_imageurl' column which works fine.
Now the problem: it is showing missing image object for 2nd and 4th row in the grid.
To solve this problem I need to set the visible property of 2nd & 4th row to false.
solution I panned:
headlines.Tables[0].Columns.Add("news_imagevisibility", System.Type.GetType("System.Boolean"), Boolean.FalseString);
so far good. All images are by default NOT Visible on the grid. so my changed DataTable looks like:
news_id news_datereleased news_source news_imageurl news_imagevisibility
------- ------------------ ------------ -------------- ---------------------
2 12-29-03 10:20 AP
http://../ap_image1.jpg false
5 12-29-03 09:30 Reuters NULL false
9 12-28-03 11:30 AFP
http://../afp_image2.jpg false
8 12-27-03 12:23 BBC NULL false
5 12-28-03 11:30 CNN
http://../cnn_image2.jpg false
7 12-27-03 12:23 AP
http://../ap_image2.jpg false
Next step is to change 'news_imagevisibility' of the DataTable as shown below
news_id news_datereleased news_source news_imageurl news_imagevisibility
------- ------------------ ------------ -------------- ---------------------
2 12-29-03 10:20 AP
http://../ap_image1.jpg true
5 12-29-03 09:30 Reuters NULL false
9 12-28-03 11:30 AFP
http://../afp_image2.jpg true
8 12-27-03 12:23 BBC NULL false
5 12-28-03 11:30 CNN
http://../cnn_image2.jpg true
7 12-27-03 12:23 AP
http://../ap_image2.jpg true
Then in asp page I will have code like this:
<asp:DataGrid .......>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:image id='..' runat="server" imageurl='<%# DataBinder.Eval(Container.DataItem,"news_imageurl" )%>'
visible='<%# DataBinder.Eval(Container.DataItem,"news_imagevisi bility")%>' >
<ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn> rest of the news info goes here </asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Code that I have written:
//use for loop to change all rows in DataTable having valid image
for(int i=0; i<headlines.Tables[0].Rows.Count; i++)
{
if ((string)headlines.Tables[0].Rows[i]["ni_turl"].GetType() != Type.GetType("System.DBNull"))
headlines.Tables[0].Rows[i]["news_imagevisibility"]=Boolean.TrueString;
}
The problem is that above loop fails to update the DataTable since it says the cell is READONLY!!!
Do you you how can I get this working???????
Thanks in Advance
Musa