javascript - ASP C# Datalist OnItemDataBound event To Change Another Cell Contents -


i'm new asp/c# , i'm working on project when runs sql stored procedure produce report based on data, , i'm populating datalist table right with 'the top 5 sql records'.

i'm having issue of accessing datalist data , i'd change aligning cell of pulled field according pulled field's value.

i have datalist setup onitembound procedure.

page code:

<asp:datalist id="datalist2" runat="server" onitemdatabound="datalist2_itemdatabound">             <headertemplate>              <table>                 <tr>                     <th>certification date</th>                     <th colspan="2">as found potential</th>                     <th>as found tolerance</th>                     <th colspan="2">as left potential</th>                     <th>as left tolerance</th>                     </tr>           </headertemplate>              <itemtemplate>                     <tr>                                                                                         <td class="td04">                                             <asp:label id="certificationdate" runat="server" text='<%# eval("as_left_date", "{0:mm/dd/yyy}") %>' /> <!-- certification date left -->                         </td>                         <td class="td05">                                             <asp:label id="asfoundpotential" runat="server" text='<%# convert.todouble(eval("as_found_entered")) %>' /> <!-- found entered -->                         </td>                         <td class="td06">                                             <div>mv</div>                         </td>                         <td class="td04">                                             <asp:label id="asfoundtolerance" runat="server" text='in tolerance' /> <!-- itemdatabound change contents -->                         </td>                         <td class="td05">                                             <asp:label id="asleftpotential" runat="server" text='<%# eval("as_left_entered") %>' /> <!-- left entered -->                         </td>                         <td class="td06">                                             <div>mv</div>                         </td>                         <td class="td04">                                             <asp:label id="aslefttolerance" runat="server" text='in tolerance' /> <!-- itemdatabound change contents -->                         </td>                                    </tr>                                 </itemtemplate>             <footertemplate>                 </table>             </footertemplate>         </asp:datalist> 

code behind:

        protected void datatable2()         {             string constr = configurationmanager.connectionstrings["records"].connectionstring;             sqlconnection conn = new sqlconnection(constr);             sqlcommand mycommand = new sqlcommand("report_page", conn);             mycommand.commandtype = commandtype.storedprocedure;                 mycommand.parameters.addwithvalue("@serial_number", serial_number.text);              dataset ds = new dataset();             sqldataadapter adp = new sqldataadapter(mycommand);              try             {                                 conn.open();                  adp.fill(ds);                 datalist2.datasource = ds.tables[0];                 datalist2.databind();                          }              catch (sqlexception ex)             {                 writetofile(environment.newline + "sql datatable2 error: " + ex.message);             }                          {                 conn.close();                 mycommand.dispose();             }         } 

ondatabound event:

        protected void datalist2_itemdatabound(object sender, datalistitemeventargs e)         {               //cell change code goes here         } 

the "in tolerance" cell/string contents change based on "as_found_entered" value double. assistance appreciated.

if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)

     {          // retrieve label control in current datalistitem.         label asfoundpotential = (label)e.item.findcontrol("asfoundpotential");      // can convert asfoundpotential lable value in double.   if (asfoundpotential = something)  {     // identify specific cell of asleftpotential  , assign whatever want change      }                                } 

hope pseudo code need put in itemdatabound event.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -