我可以在我的 ASPX 页面中创建一个自定义链接,如下所示:
<asp:GridView
ID="GridView1"
CssClass="rounded-corner"
runat="server"
AutoGenerateColumns="false"
EnableModelValidation="True"
AllowSorting="True"
onsorting="GridView1_Sorting"
EnableViewState="true"
AllowPaging="True"
PageSize="10"
OnPageIndexChanging="GridView1_PageIndexChanging" >
<Columns>
<asp:BoundField DataField="DATE_ENTERED" HeaderText="Date Submitted" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" />
<asp:BoundField DataField="CLIENT_CLAIM_NUM" HeaderText="Your Claim #" />
<asp:BoundField DataField="PRIMARY_INSURED" HeaderText="Insured" />
<asp:BoundField DataField="PRIMARY_CLAIMANT" HeaderText="Claimant" />
<asp:BoundField DataField="LOB_ID" HeaderText="Type" />
<asp:TemplateField HeaderText="Branch">
<ItemTemplate>
<asp:HyperLink ID="BRANCH_NAME" runat="server" NavigateUrl='<%# "mailto:"+Eval("OWNERS_EMAIL") %>' Text='<%# Eval("BRANCH_NAME") %>' ToolTip='<%#
"<span style=\"text-decoration:underline;\">"+Eval("BRANCH_NAME").ToString().Trim() + "</span><br />" +
Eval("OWNERS_FIRST_NAME").ToString().Trim() + " " +
Eval("OWNERS_LAST_NAME").ToString().Trim() + "<br />" +
Eval("OWNERS_EMAIL").ToString().Trim() + "<br />" +
Eval("OWNERS_OFFICE_PHONE").ToString().Trim() + "<br />" +
Eval("OWNERS_FAX_PHONE").ToString().Trim()
%> '>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
相反,是否有一种方法可以直接在我的代码中执行此操作;通过创建一种“计算字段?”
后面的代码如下:
DbProviderFactory dbf = DbProviderFactories.GetFactory();
using ( IDbConnection con = dbf.CreateConnection() )
{
string sSQL;
// 12/04/2006 Paul. Only include active users.
sSQL = "select top 20 " + ControlChars.CrLf
+ " DATE_ENTERED, CLIENT_CLAIM_NUM, PRIMARY_INSURED, PRIMARY_CLAIMANT, LOB_ID, BRANCH_NAME," + ControlChars.CrLf
+ " OWNERS_FIRST_NAME, OWNERS_LAST_NAME, OWNERS_NAME, OWNERS_EMAIL, OWNERS_OFFICE_PHONE, OWNERS_FAX_PHONE" + ControlChars.CrLf
+ " from vwFILES_DetailViewWithOwners" + ControlChars.CrLf
+ " where 1 = 1 " + ControlChars.CrLf;
using ( IDbCommand cmd = con.CreateCommand() )
{
cmd.CommandText = sSQL;
using ( DbDataAdapter da = dbf.CreateDataAdapter() )
{
((IDbDataAdapter)da).SelectCommand = cmd;
using ( DataTable dt = new DataTable() )
{
da.Fill(dt);
vwMain = dt.DefaultView;
GridView1.DataSource = vwMain;
if ( !IsPostBack )
{
GridView1.DataBind();
}
}
}
}
}
我可以简单地在我的代码中创建新字段,这样我就可以这样称呼它:
<asp:TemplateField HeaderText="Branch">
<ItemTemplate>
<asp:HyperLink ID="BRANCH_NAME"
runat="server"
NavigateUrl='<%# "mailto:"+Eval("OWNERS_EMAIL") %>'
Text='<%# Eval("BRANCH_NAME") %>'
ToolTip='<%# Eval("MY_CALCULATED_FIELD") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
谢谢你的建议。