如何根据asp.net中的条件插入多个图像?

时间:2014-12-12 04:57:42

标签: c# asp.net image file-upload

我创建了一个页面,它可以获取多个图像并将其上传到数据库。现在,我将为此插入页面创建一个编辑页面,其中所有上传的图像将显示在多个图像字段中,同时我在每个图像字段旁边提供了一个文件上载字段以便更新那特定的形象。

现在我的问题是,如果用户想要更新特定图像,用户会将另一个图像上传到文件上传,该文件上传放在该图像旁边(更新图像)并保持所有其他图像不变。那么如果文件上传中没有文件,如何从图像字段中检查并拍摄图像,否则从文件上传中获取图像。

因为,我有30多张图像需要这样处理,那么如何对每个图像字段和文件上传进行所有这些检查,并采用适当的值并使用insert语句插入。

以下是一小部分的设计代码:

<table style="width:100%;">
                        <tr>
                            <td colspan="2" style="border: thin solid #808080"><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">After Site Solarisation, any ATC material/equipments
                                <br />
                                lying idle at Site? (Ex:- Power Plant, Battery Bank, etc)</span></td>
                            <td colspan="4" style="border: thin solid #808080">
                                <asp:TextBox ID="txtIdle" runat="server" Height="25px" Width="254px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="6" style="border: thin solid #808080"><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">If Yes, List out the equipments with quantity (photographs to be attached).</span></td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080;">&nbsp;</td>
                            <td style="border: thin solid #808080;">&nbsp;</td>
                            <td style="border: thin solid #808080;">&nbsp;</td>
                            <td style="border: thin solid #808080;">&nbsp;</td>
                            <td style="border: thin solid #808080;">&nbsp;</td>
                            <td style="border: thin solid #808080;">&nbsp;</td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080; text-align: center"><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA;mso-bidi-font-weight:bold">ITEMS</span></td>
                            <td style="border: thin solid #808080; text-align: center"><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">UOM</span></td>
                            <td style="border: thin solid #808080; text-align: center"><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">QTY</span></td>
                            <td style="border: thin solid #808080; text-align: center"><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">PHOTOS</span></td>
                            <td style="border: thin solid #808080; text-align: center; "><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">UPDATE PHOTOS</span></td>
                            <td style="border: thin solid #808080; text-align: center; "><span style="font-size:11.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;
mso-fareast-font-family:Calibri;mso-bidi-font-family:Calibri;mso-bidi-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA">REMARKS</span></td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelItems1" runat="server" Height="25px" Width="254px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelUOM1" runat="server" Height="25px" Width="169px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelQty1" runat="server" Height="25px" TextMode="Number" Width="103px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:Image ID="ImgIdel1" runat="server" Height="100px" Width="100px" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:FileUpload ID="fuIdelPhoto1" runat="server" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:TextBox ID="txtIdelRemarks1" runat="server" Height="25px" Width="196px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelItems2" runat="server" Height="25px" Width="254px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelUOM2" runat="server" Height="25px" Width="169px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelQty2" runat="server" Height="25px" TextMode="Number" Width="103px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:Image ID="ImgIdel2" runat="server" Height="100px" Width="100px" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:FileUpload ID="fuIdelPhoto2" runat="server" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:TextBox ID="txtIdelRemarks2" runat="server" Height="25px" Width="196px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelItems3" runat="server" Height="25px" Width="254px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelUOM3" runat="server" Height="25px" Width="169px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelQty3" runat="server" Height="25px" TextMode="Number" Width="103px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:Image ID="ImgIdel3" runat="server" Height="100px" Width="100px" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:FileUpload ID="fuIdelPhoto3" runat="server" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:TextBox ID="txtIdelRemarks3" runat="server" Height="25px" Width="196px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelItems4" runat="server" Height="25px" Width="254px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelUOM4" runat="server" Height="25px" Width="169px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelQty4" runat="server" Height="25px" TextMode="Number" Width="103px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:Image ID="ImgIdel4" runat="server" Height="100px" Width="100px" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:FileUpload ID="fuIdelPhoto4" runat="server" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:TextBox ID="txtIdelRemarks4" runat="server" Height="25px" Width="196px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelItems5" runat="server" Height="25px" Width="254px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelUOM5" runat="server" Height="25px" Width="169px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:TextBox ID="txtIdelQty5" runat="server" Height="25px" TextMode="Number" Width="103px"></asp:TextBox>
                            </td>
                            <td style="border: thin solid #808080; text-align: center;">
                                <asp:Image ID="ImgIdel5" runat="server" Height="100px" Width="100px" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:FileUpload ID="fuIdelPhoto5" runat="server" />
                            </td>
                            <td style="border: thin solid #808080; text-align: center; ">
                                <asp:TextBox ID="txtIdelRemarks5" runat="server" Height="25px" Width="196px"></asp:TextBox>
                            </td>
                        </tr>
                    </table>

请帮助,完全困惑,任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以使用会话来跟踪上传到服务器的图像。 例如,当您的每个新文件都已更新到记录时,该特定图像的上载日期时间。例如,您可以对图像加载功能执行某些操作。

    Dictionary<string,DateTime> ImageUploadDictionary = new Dictionary<string,DateTime>();

当图像文件夹有新的更新时。做点什么         ImageUploadDictionary.add(“ImageName”,DateTime.Now);

将字典存储在会话中,因此您可以在表单提交时访问最新的字典。我不太确定这是否能回答你的问题:)