1

I am using html template for Email and i want to hide its one table at some condition by code behind, how can i do it, please suggest me. I am wondering how can i do it, i am not able to find any way, please suggest me any way to come out from this, thanks in advance. My code is :

if (File.Exists(appPath + "\\rptBookDetails.Template"))
        {
            FinalOutPut = File.ReadAllText(appPath + "\\rptBookDetails.Template");

            FinalOutPut = FinalOutPut.Replace("{AccessionNo}", dsBookDetails.Tables[0].Rows[0]["AccessionNo"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Title}", dsBookDetails.Tables[0].Rows[0]["TITLE"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Edition}", dsBookDetails.Tables[0].Rows[0]["EDITION"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Volume}", dsBookDetails.Tables[0].Rows[0]["Volume"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Authors}", dsBookDetails.Tables[0].Rows[0]["Authors"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Pages}", dsBookDetails.Tables[0].Rows[0]["PAGES"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Publication}", dsBookDetails.Tables[0].Rows[0]["PUB_PLACE"].ToString());
            FinalOutPut = FinalOutPut.Replace("{PublicationYear}", dsBookDetails.Tables[0].Rows[0]["YEAR_O_PUB"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Price}", dsBookDetails.Tables[0].Rows[0]["COST"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Supplier}", dsBookDetails.Tables[0].Rows[0]["AccessionNo"].ToString());
            FinalOutPut = FinalOutPut.Replace("{BillNo}", dsBookDetails.Tables[0].Rows[0]["BILL_NO"].ToString());
            FinalOutPut = FinalOutPut.Replace("{BillDate}", dsBookDetails.Tables[0].Rows[0]["DT_O_BILL"].ToString());
            FinalOutPut = FinalOutPut.Replace("{Grant Source}", dsBookDetails.Tables[0].Rows[0]["GRANT_SR"].ToString());

        }

What i want to do is, in case i dont have books detail in database then i dont want to show the table in HTML out put. please help me

<table width="84%" border="1" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="30%" align="left" valign="top">
                    Accession No.
                </td>
                <td width="2%">
                    :
                </td>
                <td width="68%" align="left" valign="top">
                    B10
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Title
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Title}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Edition
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Edition}
                </td>
            </tr>
        <tr>
            <td align="left" valign="top">
                    Volume
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Volume}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Authors
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Authors}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Pages
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Pages}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <td align="left" valign="top">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Publication Place
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Publication}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Publication Year
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {PublicationYear}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <td align="left" valign="top">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Price
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Price}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Source of Purchase
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Supplier}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Bill No.
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {BillNo}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Bill Date
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {BillDate}
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    Grant Source
                </td>
                <td>
                    :
                </td>
                <td align="left" valign="top">
                    {Grant Source}
                </td>
            </tr>
    </table>

<table width="97%" id="tblHistry" border="1" align="center" cellpadding="2" cellspacing="0">
            <tr>
                <th>
                    Sr
                </th>
                <th>
                    Trans. Id
                </th>
                <th>
                    Borrower Id
                </th>
                <th>
                    Issue Date
                </th>
                <th>
                    Expected Return Date
                </th>
                <th>
                    Actual Return Date
                </th>
                <th>
                    Fine
                </th>
                <th>
                    Fine Status
                </th>
                <th>
                    Issue Remarks
                </th>
                <th>
                    Return Remarks
                </th>
            </tr>
            {HistoryTable}
        </table>

I want to Hide and Show tblHistry on condition, please help me.

4

2 回答 2

3

使用asp面板控件并将您的表格放在该面板内......现在在特定事件代码中的文件后面的代码中

Panelname.visible=true;

或者

Panelname.visible=false;
于 2013-04-08T07:44:09.483 回答
1

考虑到您的表是动态创建的并存储在字符串中而不是控件。

有两种方法可以满足您的需求;

方式一

修改模板并在要隐藏/显示的表格中包含另一个要替换的标签style="{CSSStyle}" 。

<table width="97%" id="tblHistry" style="{CSSStyle}" border="1" align="center" cellpadding="2" cellspacing="0">

在后面的代码中执行以下操作以显示表格;

 FinalOutPut = FinalOutPut.Replace("{CSSStyle}", "");

而在下面隐藏它;

  FinalOutPut = FinalOutPut.Replace("{CSSStyle}", "display:none");

方式二

在 2 个自定义标签中关闭 tblHitry 表,如下所示;

[HistoryTable]
   <table width="97%" id="tblHistry" cellpadding="2" cellspacing="0">
     ....
   </table>
[/HistoryTable]

在代码后面的代码中,使用下面的代码隐藏和显示表格;

string strHistoryTableOpeningTag = "[HistoryTable]";
string strHistoryTableClosingTag = "[/HistoryTable]";
int intStartPos = 0;
int intEndPos = 0;

if (blnWantToHide == True) {
  //Remove history table
  intStartPos = FinalOutPut.IndexOf(strHistoryTableOpeningTag);
  intEndPos = FinalOutPut.IndexOf(strHistoryTableClosingTag) + strHistoryTableClosingTag.Length;

 FinalOutPut = FinalOutPut.Remove(intStartPos, intEndPos - intStartPos);
} else {
  //Remove unwanted tags
  FinalOutPut = FinalOutPut.Replace(strHistoryTableOpeningTag, "");
  FinalOutPut = FinalOutPut.Replace(strHistoryTableClosingTag, "");
}

就我个人而言,我会选择方式 2,因为它更整洁,而且您不会有不需要的隐藏 HTML。

于 2013-04-08T08:18:29.983 回答