asp.net - GridView Calculated Field -
i can create custom link in aspx page this:
<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>
is there, instead, way straight in code behind; creating type of "calculated field?"
the code behind follows:
dbproviderfactory dbf = dbproviderfactories.getfactory(); using ( idbconnection con = dbf.createconnection() ) { string ssql; // 12/04/2006 paul. 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 + " vwfiles_detailviewwithowners" + controlchars.crlf + " 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(); } } } } }
can create new field in code behind can phone call so:
<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>
thanks advice.
you can create function in c# code format data. article on msdn talks it: http://msdn.microsoft.com/en-us/library/bb288032.aspx#aspnett12ustmpfldsvb_topic5
to summarize, alter item template this:
<itemtemplate> <asp:hyperlink id="branch_name" runat="server" navigateurl='<%# "mailto:"+eval("owners_email") %>' text='<%# eval("branch_name") %>' tooltip='<%# getbranchaddress(ctype(container.dataitem, system.data.datarowview).row) %> '> </asp:hyperlink> </itemtemplate>
and in c#, create function this:
protected string getbranchaddress(datarow row) { homecoming "<span style=\"text-decoration:underline;\">"+ row["branch_name"].tostring().trim() + "</span><br />" + row["owners_first_name"].tostring().trim() + " " + row["owners_last_name"].tostring().trim() + "<br />" + row["owners_email"].tostring().trim() + "<br />" + row["owners_office_phone"].tostring().trim() + "<br />" + row["owners_fax_phone"].tostring().trim(); }
this approach nice because can set breakpoints in c# function , add together error handling, etc.
asp.net gridview webforms
No comments:
Post a Comment