6

我的数据库中的一个表存储了图片、文档、dll 吊索等。如何为用户实现所有这些的映射?我将这些数据绑定到一个数据表,并希望在每个单元格中都有超链接,当单击它时,会从数据库中调用/打开相应的项目。

OracleCommand oracleCom = new OracleCommand();
oracleCom.Connection = oraConnect;
oracleCom.CommandText = "Select * From " + Session["tableNameIns"];
OracleDataAdapter adapter = new Oraenter code herecleDataAdapter();
DataTable tableD = new DataTable();
tableD.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.SelectCommand = oracleCom;
adapter.Fill(tableD);
changeTableAtributs(tableD);
tableResults.DataSource = tableD.AsDataView();
tableResults.DataBind();

在 DB 中的下一个属性:i_id(number)、i_objecttype_id(number)、s_code(nvarchar)、s_name(nvarchar)、m_content(blob)、m_description(nvarchar) 数据库视图

在客户端我看到下一个:i_id(number)、i_objecttype_id(number)、s_code(nvarchar)、s_name(nvarchar)、m_description(nvarchar)。没有属性 m_content。 客户端视图

4

6 回答 6

1

看来你的问题是“不完整的”。因此,如果 blob 是图片,您希望显示该图片吗?如果 blob 是 dll 会发生什么?

在您的数据库中,M_CONTENT 字段是一个 blob,因此如果您将其数据绑定到 GridView,则 GridView 无法知道该字段中的内容。

如果要显示图像以显示 blob 中文件的类型,则需要知道类型。要么将类型存储在数据库中(最佳),要么在运行时解析 blob 并找出文件类型。

在我看来,您已经拥有类型 (I_OBJECTTYPE_ID)。如果是这种情况,那么您可以在 asp:GridView/Columns 下定义一个列

<asp:TemplateField HeaderText="File type">
    <ItemTemplate>
        <asp:Image runat="server" ID="mediaImage"
            ImageUrl='<%# GetImageUrl(Eval("type") as string) %>' />
    </ItemTemplate>
</asp:TemplateField>

在您的情况下,类型列称为 I_OBJECTTYPE_ID。GetImageUrl 是代码隐藏中的一个函数:

switch (type)
{
    case "video":
        return "~//Images//video.png";
    case "audio":
        return "~//Images//audio.png";
}
return ""; // Something is wrong

使用这种技术,您可以在 ItemTemplate 标记下制作超链接和其他内容。

于 2012-12-06T22:26:50.400 回答
0

您可以在 GridView 的 RowDataBound 事件中获取这些值并创建链接/超链接并将它们分配给行

    protected void tableResults_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView row = e.Row.DataItem as DataRowView;

            if (row != null)
            {
                Label lbImagePath = e.Row.FindControl("lbImagePath") as Label;
                lbImagePath.Text = row["ImagePathColumn"].ToString();
            }
        }
    }

在您的情况下,将该标签更改为超链接控件并将其 URL 设置为列值

于 2012-11-29T22:22:00.990 回答
0

如果您想让用户下载文件而不是显示(因为 dll 可以在浏览器上显示),请执行以下操作:

  1. 创建一个新页面说downloadfile.aspx
  2. datarowbound事件中解析下载文件所需的值,如文件类型、文件名等;假设您已保存abc.pdf为 blob,那么超链接 url 应该是downloadfile.aspx?fname=abc.pdf&type=application&pkey=uniqueidentification
  3. downloadfile.aspx加载事件中获取byte[]基于uniqueidentification(即主键)的blob。将其转换为流,然后像在这个问题中一样给出回应。
于 2012-12-27T12:05:21.043 回答
0

为此,您必须使用TemplateField。您将向每个单元格插入控件并使用Eval函数绑定数据。有关更多信息,请参阅此链接

于 2013-01-02T07:09:09.453 回答
0

为每一行制作网格按钮并使用选择或删除或更新按钮。

e.selectedindex。

您可以随时更改标题或隐藏标题。

你也可以使用像selectedindexchanged这样的事件,所以一旦你选择了你就可以得到选择的索引id,所以使用它可以调用方法

于 2013-01-05T18:01:38.490 回答
0

这样做,在TemplateField中你有EditTemplateFieldItemTemplateField,在 ItemTemplateField 中输入你的列名 Ex: Age: 并在 Text Bind("Age") 和 ItemTemplate 中从 EditTemplate 复制所有内容并将其粘贴,不要完全复制我的代码例如,我已将代码显示在表格中。因此,现在您可以编辑 HTML 之类的所有内容,只需将链接作为 href 即可。

<asp:GridView ID="GridViewFemale" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="LinqDataSourceFemale" Width="158px">
    <Columns>
         <asp:ImageField DataImageUrlField="Image" NullImageUrl="images/INA.jpg" ShowHeader="False"></asp:ImageField>
        <asp:TemplateField>
            <EditItemTemplate>
                <table>
                    <tr>

                        <td>
                             <b> Age:</b> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Age") %>'></asp:Label><br />
                            <b> Name:</b> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
                            <b> Education:</b> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Education") %>'></asp:Label><br />
                            <b> Current Status:</b> <asp:Label ID="Label4" runat="server" Text='<%# Bind("CurrentStatus") %>'></asp:Label><br />
                            <b> Height:</b> <asp:Label ID="Label5" runat="server" Text='<%# Bind("Height") %>'></asp:Label><br />
                            <b> Complexion:</b> <asp:Label ID="Label6" runat="server" Text='<%# Bind("Complexion") %>'></asp:Label><br />
                            <b> Caste:</b> <asp:Label ID="Label7" runat="server" Text='<%# Bind("Caste") %>'></asp:Label><br />
                            <b> Group:</b> <asp:Label ID="Label8" runat="server" Text='<%# Bind("Group") %>'></asp:Label>
                        </td>
                    </tr>
                </table>
            </EditItemTemplate >
            <ItemTemplate>
                <table id="GridTable">
                    <tr>

                        <td>
                             <b> Age:</b> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Age") %>'></asp:Label><br />
                            <b> Name:</b> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
                            <b> Education:</b> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Education") %>'></asp:Label><br />
                            <b> Current Status:</b> <asp:Label ID="Label4" runat="server" Text='<%# Bind("CurrentStatus") %>'></asp:Label><br />
                            <b> Height:</b> <asp:Label ID="Label5" runat="server" Text='<%# Bind("Height") %>'></asp:Label><br />
                            <b> Complexion:</b> <asp:Label ID="Label6" runat="server" Text='<%# Bind("Complexion") %>'></asp:Label><br />
                            <b> Caste:</b> <asp:Label ID="Label7" runat="server" Text='<%# Bind("Caste") %>'></asp:Label><br />
                            <b> Group:</b> <asp:Label ID="Label8" runat="server" Text='<%# Bind("Group") %>'></asp:Label>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
于 2013-03-31T18:27:57.500 回答