【Vegas原创】Datagrid中图片按条件显示的解决

需求: 某表单如果有附件,则显示图片;如果没有,则不显示。

解决方案:
1.建一个Datagrid名为Result,form_no栏位是键接栏,最后一列是附件,用模版列。

    <asp:datagrid id="Result" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 280px" runat="server"
                Width="728px" Height="149px" Visible="False" AutoGenerateColumns="False" Font-Size="Smaller">
                        <Columns>
                            <asp:HyperLinkColumn DataNavigateUrlField="form_no" DataNavigateUrlFormatString="SelectResult.asp?form_no={0}"
                                DataTextField="form_no" HeaderText="表单号"></asp:HyperLinkColumn>
                            <asp:BoundColumn DataField="form_status" HeaderText="状态"></asp:BoundColumn>
                            <asp:BoundColumn DataField="doc_no" HeaderText="异常通知单号"></asp:BoundColumn>
                            <asp:BoundColumn DataField="date_app" HeaderText="开立日期"></asp:BoundColumn>
                            <asp:BoundColumn DataField="PS_FZ" HeaderText="责任人员"></asp:BoundColumn>
                            <asp:BoundColumn DataField="PS_JA" HeaderText="结案负责人员"></asp:BoundColumn>
                            <asp:BoundColumn DataField="MS_XX" HeaderText="异常现象描述"></asp:BoundColumn>
                            <asp:TemplateColumn HeaderText="附件">
                                <HeaderTemplate>
                                    <FONT face="宋体">附件</FONT>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <FONT face="宋体">
                                        <asp:Image id="Image1" runat="server" Visible="False" ImageUrl="../img/wenjian1.GIF"></asp:Image></FONT>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                        </Columns>
            </asp:datagrid>


2.后台处理代码:

    //显示附件
            string form_no=Request.QueryString["Form_No"];
            DataSet dsFile
=MyConn.GetFile("BQS.FORM.T601");
            
if(dsFile.Tables["File"].Rows.Count!=0)
            {
                
                ArrayList alFormNo
=new ArrayList();
                
for(int j=0;j<dsFile.Tables["File"].Rows.Count;j++)
                    alFormNo.Add(dsFile.Tables[
"File"].Rows[j]["FORM_NO"].ToString());
                
for(int i=0;i<Result.Items.Count;i++)
                {
                    
string strFormNo=((HyperLink)Result.Items[i].Cells[0].Controls[0]).Text.ToString();
                    
                    
if(alFormNo.IndexOf(strFormNo)!=-1)
                        ((System.Web.UI.WebControls.Image)Result.Items[i].FindControl(
"Image1")).Visible=true;
                }
            }

 

posted @ 2006-10-13 14:02  李济宏(Amadeus)  阅读(150)  评论(0编辑  收藏  举报