Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display different objects in gridview?

A table in my database has stored pictures, documents, dll halyards and so on. How do I implement the mapping of all this for a user? I bind these data to a data table, and want to have hyperlinks in each cell, which when clicked, invokes/opens the corresponding item from the database.

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();

In DB next atributes: i_id(number), i_objecttype_id(number), s_code(nvarchar), s_name(nvarchar), m_content(blob), m_description(nvarchar) dbview

On client I see next: i_id(number), i_objecttype_id(number), s_code(nvarchar), s_name(nvarchar), m_description(nvarchar). Without atribute m_content. clienview

like image 590
Tleck Aipov Avatar asked Nov 06 '12 04:11

Tleck Aipov


1 Answers

It seems your question is "incomplete". So if the blob is a picture you want the picture to be displayed? What should happen if the blob is a dll?

In your database the M_CONTENT field is a blob so if you databind that to a GridView the GridView has no way of knowing what is in that field.

If you want an image displayed to show the type of the file in the blob then you need to know the type. Either you store the type in the database (Optimal) or you parse the blob at runtime and figure out the file type.

It seems to me that you already have the type (I_OBJECTTYPE_ID). If that is the case then you can define a column under asp:GridView/Columns

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

In your case the type column is called I_OBJECTTYPE_ID. The GetImageUrl is a function in the codebehind:

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

And using this technique you can make Hyperlinks and other stuff under the ItemTemplate markup.

like image 172
Viktor Avatar answered Oct 31 '22 02:10

Viktor