2012-11-06 34 views
6

我的數據庫中的表格存儲了圖片,文檔,dll halyards等。如何爲用戶實現所有這些映射? 我將這些數據綁定到數據表,並且希望在每個單元格中都有超鏈接,單擊它們時會從數據庫調用/打開相應的項目。如何在gridview中顯示不同的對象?

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未來atributes:i_id(號),i_objecttype_id(號),s_code(NVARCHAR),S_NAME(NVARCHAR),m_content(BLOB),m_description(NVARCHAR) dbview

在客戶端我請參閱:i_id(number),i_objecttype_id(number),s_code(nvarchar),s_name(nvarchar),m_description(nvarchar)。 沒有屬性m_content。 clienview

+6

請詳細解釋您的情況,以便每個人都能理解您的問題。如果可能的話,用簡單的例子來解釋。您提供的信息越多,解決方案就越好。 –

+0

請用示例來解釋更多.. –

+1

使用Interface和BindingSource怎麼樣? – Tobias

回答

1

看來您的問題是「不完整」。所以如果斑點是你想要顯示圖片的圖片?如果blob是一個DLL會發生什麼?

在你的數據庫中,M_CONTENT字段是一個blob,所以如果你把它綁定到一個GridView上,GridView無法知道該字段是什麼。

如果您希望顯示的圖像顯示blob中文件的類型,那麼您需要知道類型。要麼將類型存儲在數據庫中(Optimal),要麼在運行時解析blob並找出文件類型。

在我看來,你已經有了類型(I_OBJECTTYPE_ID)。如果是這樣的話,那麼你可以在ASP定義列:GridView控件/列

<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中標記下。

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

你的情況變化列值的網址

+0

我打算顯示不同的對象。不是鏈接。 –

+0

你是什麼意思的不同對象? – Sev

+1

是的,你在你原來的問題中說你想在每個單元中有超鏈接。 – lintmouse

0

如果你想要讓用戶下載,而不是顯示(因爲可以在瀏覽器中顯示DLL)文件然後執行如下:

  1. 創建一個新的頁面說downloadfile.aspx;
  2. datarowbound事件解析文件類型,文件名等下載文件 所需的值;假設你已經將abc.pdf保存爲blob,那麼超鏈接url應該是downloadfile.aspx?fname=abc.pdf&type=application&pkey=uniqueidentification;
  3. downloadfile.aspx加載事件根據uniqueidentification(即主鍵)獲得blob爲byte[]。將它轉換成流,然後在this question中給予響應。
0

要實現這一點,必須使用的TemplateField。您將控制插入到每個單元格並綁定數據使用Eval函數。欲瞭解更多信息,請參閱該link

0

使電網按鈕,每一行和使用選擇或刪除或更新按鈕。

e.selectedindex。

你可以隨時更改標題或隱藏標題。

ü也可以使用事件,如的SelectedIndexChanged,所以一旦ü選擇u得到所選擇的索引ID,以便使用可調用方法

0

不喜歡這一點,在模板列你有EditTemplateFieldItemTemplateField,在ItemTemplateField中添加列名Ex:Age:並在Text Bind(「Age」)和ItemTemplate中複製EditTemplate中的everythinh,然後粘貼它們,不要完全複製我的代碼這是示例,我已將代碼顯示在表中。所以現在你可以編輯像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> 
相關問題