c# - Integer only validation for dynamically added Textbox inside Asp.net Gridview -
below how gridview code , since datatable pivoted value number of columns cannot predicted. adding textbox dynamically through code.
<asp:gridview id="gvdata" emptydatatext="there no data records display." runat="server" autogeneratecolumns="false" headerstyle-backcolor="#3ac0f2" headerstyle-forecolor="white" onrowdatabound="gvdata_rowdatabound" > <rowstyle bordercolor="lightblue" /> </asp:gridview> protected void page_load(object sender, eventargs e) { foreach (var item in columnnames) { templatefield tfield = new templatefield(); tfield.headertext = item; gvdata.columns.add(tfield); } gvdata.datasource = ds.tables[0]; gvdata.databind();} protected void gvdata_rowdatabound(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.datarow) { (int = 3; < columnnames.length; i++) { textboxcount++; textbox txtname = new textbox(); txtname.id = "txt" + convert.tostring(textboxcount); txtname.borderstyle = borderstyle.none; txtname.text = (e.row.dataitem datarowview).row[columnnames[i]].tostring(); e.row.cells[i].controls.add(txtname); }}}
now when user try change value in textbox have validate enter integer value. here not sure has done.
you can use int.tyrparse method
example
int number; string s = "aa"; bool isinteger = int.tryparse(s, out number);
Comments
Post a Comment