c# - Dataset datatable formatting rows -


hi have dataset contains table retrieved sql. has 'product' column , 'price' column. got dataset , binded grid. want make grid's price column formatted 2 decimal places(validation). idea please. should not change select query since sp gives me dataset.

if neither want use bound-field nor change select query know have 2 options left accomplish this. first is, value change in dataset before binding grid using loop , second option alter values in grid on rowdatabound event...

by altering value in dataset:

 foreach(datarow[] dr in dataset.tables[your table index])  {   // max. 2 decimal places    string val =   string.format("{0:0.##}",convert.todecimal(dr[column index]));     dr[column index] = val;  } 

by altering value in grid:

  protected void mygrid_onrowdatabound(object sender, gridviewroweventargs e)     {         if (e.row.rowtype == datacontrolrowtype.datarow)         {             mygrid.cell[cell index].text =   string.format("{0:0.##}",convert.todecimal(dataset.tables[table index][column index][row index]));                         }     } 

now if want apply validation data insert , update can apply regularexpressionvalidator @ textbox ...

   <edititemtemplate>   <asp:textbox id="textbox1" runat="server"></asp:textbox>     <asp:regularexpressionvalidator id="regularexpressionvalidator1" runat="server"     errormessage="regularexpressionvalidator"         controltovalidate="textbox1" validationexpression="^\d{1,2}([.]\d{1})$"> validationgroup="myval"</asp:regularexpressionvalidator> 

now have apply

validationgroup="myval"

also on click control on you'll perform editing , update..


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -