我在問這是因爲我從Exchange Server訪問郵件。郵件正文包含HTML。要顯示郵件的正文,我使用FreeTextBox控件。但我有很多郵件,我首先在gridview中顯示。但問題是在網格視圖單元格中顯示的正文中的HTML。是否有可能把一個FreeTextBox的GridView的每個記錄?是否可以將控件放入另一個控件中?
歡迎任何幫助
這是我使用綁定代碼/等
private DataTable dt;
private ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
dt = new DataTable();
MakeDataTable();
ConnectToExchange();
DoorloopMailbox();
BindGrid();
}
else
{
dt = (DataTable)ViewState["DataTable"];
}
ViewState["DataTable"] = dt;
//service.TraceEnabled = true; --om te traceren.
}
private void ConnectToExchange()
{
service.Credentials = new NetworkCredential("user", "pass", "domain.com");
service.Url = new Uri("Uri");
}
private void DoorloopMailbox()
{
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox,
new ItemView(100));
foreach (Item item in findResults.Items)
{
item.Load();
DataRow dr = dt.NewRow();
dr["OutlookID"] = item.Id.UniqueId;
//dr["Sender"] = item.
dr["Subject"] = item.Subject;
string processedInput;
string omschrijving = item.Body;
if (omschrijving != null)
{
processedInput = Regex.Replace(omschrijving, @"<(.|\n)*?>", string.Empty);
}
else
{
processedInput = "geen omschrijving";
}
dr["Body"] = processedInput;
dr["Sent"] = item.DateTimeSent;
dt.Rows.Add(dr);
}
}
private void BindGrid()
{
gvAanvragen.DataSource = dt;
gvAanvragen.DataBind();
}
private void MakeDataTable()
{
dt.Columns.Add("OutlookID");
dt.Columns.Add("Sender");
dt.Columns.Add("Subject");
dt.Columns.Add("Body");
dt.Columns.Add("Sent");
}
protected void GvMeldingen_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("Detailscherm.aspx?melder=" + Server.UrlEncode(gvMeldingen.SelectedRow.Cells[3].Text)
+ "&datum=" + gvMeldingen.SelectedRow.Cells[6].Text
+ "&onderwerp=" + Server.UrlEncode(gvMeldingen.SelectedRow.Cells[4].Text)
+ "&id=" + Server.UrlEncode(gvMeldingen.SelectedRow.Cells[1].Text)
+ "&omschrijving=" + Server.UrlEncode(gvMeldingen.SelectedRow.Cells[5].Text));
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void GvAanvragen_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvAanvragen.PageIndex = e.NewPageIndex;
BindGrid();
}
這是設計視圖代碼:
<asp:GridView ID="gvAanvragen"
OnPageIndexChanging="GvAanvragen_PageIndexChanging" runat="server" AllowPaging="True"
AllowSorting="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"
PageSize="5">
<RowStyle BackColor="#F7F7DE" />
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
我們需要更深入。我們可以在控件內創建一個控件嗎? – mquander 2011-03-08 14:29:33
Tassisto:看到我更新的答案。 – Peter 2011-03-08 14:40:20
@Patricker我怎樣才能完全隱藏一個列,但仍然檢索它的值? – SamekaTV 2011-03-11 07:29:39