Display datagrid records

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi All

I currently use the following codes to display images from a DataGrid but it
can only display 1 per line. May I know whether how can I display multiple
pics(records) per line in the DataGrid ? Or if DataGrid is not the best way
to do so, any other better methods to do the task ?

<asp:DataGrid id="myGrid" runat="server" CellPadding="2" BorderWidth="0px"
Width="100%" CssClass="cntltext" DataKeyField="Filename"
AutoGenerateColumes="False" AutoGenerateColumns="False">
<HeaderStyle font-bold="True" forecolor="PaleGoldenrod"
backcolor="MidnightBlue"></HeaderStyle>
<AlternatingItemStyle backcolor="#D0D0FF"></AlternatingItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Image View">
<ItemTemplate>
<img src="<%# DataBinder.Eval(Container.DataItem,"ImageFullPath") %>"/
width="100" height="75" >
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks
Peter
 
Hi All

I currently use the following codes to display images from a DataGrid butit
can only display 1 per line.   May I know whether how can I display multiple
pics(records) per line in the DataGrid ?  Or if DataGrid is not the best way
to do so, any other better methods to do the task ?

 <asp:DataGrid id="myGrid" runat="server" CellPadding="2" BorderWidth="0px"
Width="100%" CssClass="cntltext" DataKeyField="Filename"
AutoGenerateColumes="False" AutoGenerateColumns="False">
  <HeaderStyle font-bold="True" forecolor="PaleGoldenrod"
backcolor="MidnightBlue"></HeaderStyle>
  <AlternatingItemStyle backcolor="#D0D0FF"></AlternatingItemStyle>
  <Columns>
      <asp:TemplateColumn HeaderText="Image View">
   <ItemTemplate>
    <img src="<%# DataBinder.Eval(Container.DataItem,"ImageFullPath") %>"/
width="100" height="75" >
   </ItemTemplate>
      </asp:TemplateColumn>
  </Columns>
 </asp:DataGrid>

Thanks
Peter

If you have fixed number of images for each item (for example, 3) then
you can just have 3 <img /> in the <ItemTemplate> tag. If number may
vary the best choice would probably be a nested datalist
 
Hi Mark

Thanks for your help again. My images per row cam from different records rather than different fields. Any suggestions, if I need
to change from DataGrid from GridView (assuming the datasourse part is unchanged, how would I change the code with DataGrid par ?

Thanks
Peter
 
Hi Alex

No, the number of records are not fixed but I want to control the number of pics per row instead of only 1

Thanks
Peter

Hi All

I currently use the following codes to display images from a DataGrid but it
can only display 1 per line. May I know whether how can I display multiple
pics(records) per line in the DataGrid ? Or if DataGrid is not the best way
to do so, any other better methods to do the task ?

<asp:DataGrid id="myGrid" runat="server" CellPadding="2" BorderWidth="0px"
Width="100%" CssClass="cntltext" DataKeyField="Filename"
AutoGenerateColumes="False" AutoGenerateColumns="False">
<HeaderStyle font-bold="True" forecolor="PaleGoldenrod"
backcolor="MidnightBlue"></HeaderStyle>
<AlternatingItemStyle backcolor="#D0D0FF"></AlternatingItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Image View">
<ItemTemplate>
<img src="<%# DataBinder.Eval(Container.DataItem,"ImageFullPath") %>"/
width="100" height="75" >
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks
Peter

If you have fixed number of images for each item (for example, 3) then
you can just have 3 <img /> in the <ItemTemplate> tag. If number may
vary the best choice would probably be a nested datalist
 
The DataSource comes from below where dvImageList is a DataView object.

myGrid.DataSource = dvImageList;
myGrid.DataBind();


Thhanks

Peter said:
Hi Mark

Thanks for your help again. My images per row cam from different records rather than different fields. Any suggestions, if I
need to change from DataGrid from GridView (assuming the datasourse part is unchanged, how would I change the code with DataGrid
par ?

Thanks
Peter
 
I tried to modify my codes as below and its so strange that ALL fields in myGrid appears as individual columns automatically ? As
seen below, I expect nothing to be shown but I guess it's not what I expected.

<asp:GridView id="myGrid" runat="server" CellPadding="2" BorderWidth="0px" Width="100%" CssClass="cntltext" >
<HeaderStyle font-bold="True" forecolor="PaleGoldenrod" backcolor="MidnightBlue"></HeaderStyle>
<Columns>
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Thanks
Peter

Peter said:
The DataSource comes from below where dvImageList is a DataView object.

myGrid.DataSource = dvImageList;
myGrid.DataBind();


Thhanks
 
Sorry guys, I ommit the AutoGenerateColumns and that's why all columns appeared. Can you give me a hand on how to put fields on
multiple records on the same line ?

Thanks
 
Back
Top