Posts

javascript - How to make the user save a text box value as an image or file to their machine in html5 using jQuery -

what best way make user save text box value out use of server side scripting . using html5 , jquery . tried printing textbox putting inside iframe print() function of javascript , worked , want know whether other alternatives available .

javascript - How to set id to a <tr> generated from a JSON response? -

i want set id's dynamically rows. have this: function (json) { (var ib = 0; ib < json.length; ib++) { var tableib = document.getelementbyid("treatments"); var treatmentid = json[ib].id; var rowib = tableib.insertrow(-1); var cell1ib = rowib.insertcell(0); var cell2ib = rowib.insertcell(1); var cell3ib = rowib.insertcell(2); var cell4ib = rowib.insertcell(3); var cell5ib = rowib.insertcell(4); var buttonid = json[ib].id; cell1ib.innerhtml = json[ib].name; cell2ib.innerhtml = json[ib].time; cell3ib.innerhtml = json[ib].price + "kr"; cell4ib.innerhtml = json[ib].details; cell5ib.innerhtml = "button"; } }); the id want set json response , has variable buttonid . possible or should append each row this? : $('#treatments').append("<tr><td...

asp.net mvc - Conditional validation on model in MVC -

i have view & model use both edit , insert page record. 1 of business requirements field required on edit not on new. before particular feature added docket, had model so: [required(errormessage = "*")] [range(0.0, (double)decimal.maxvalue)] [displayname("cost")] [displayformat(dataformatstring = "{0:d}", applyformatineditmode = true)] public decimal proposedcost { get; set; } i either remove required property if insert form, or add if edit form. better approach? other validation done above. or can alter model state? thoughts? edit something should clarify still permitted insert cost on new, not required. if you're on mvc3/.net4, can use ivalidatableobject exists such purposes. quoting scottgu , ...the ivalidatableobject interface enables perform model-level validation, , enables provide validation error messages specific state of overall model.... you model like public class myviewmodel : ivalidatableobject { ...

Convert C realloc to Delphi -

int stackrealloc(stack* s){ if ((s->array = realloc(s->array,sizeof(int)*(s->size)*2)) != null){ s->size = (s->size)*2; return 1; } else return 0; } how can convert code( c ) delphi ( delphi7 ) ? the delphi function analagous c realloc reallocmem . you could, if wished, make literal translation of c struct delphi record, , call reallocmem . in delphi use dynamic array instead of raw pointers: var arr: array of integer; ... setlength(arr, length(arr)*2); there's no need struct contains both array , size because delphi dynamic array keeps track of own length. what's more not signal errors using 0 or 1 return value. instead not write explicit error checking in code , let runtime raise exception should call setlength fail. since appear implementing stack, use tstack class found in contnrs unit. in modern delphi use generics.collections.tstack<integer> instead. as aside, c code broken. fails handle errors correc...

Connection property has not been initialized c# -

im getting when execute non query .. calling executenonquery.... clsconnection.executenonquery("add_customers", commandtype.storedprocedure, paramlist); exception pop @ cmd.connection.open(); this whole executenonquery public static void executenonquery(string sql, commandtype type, list<sqlparameter> paramlist) try { dataaccess.clsconnection clsdb = new dataaccess.clsconnection(); using (sqlconnection cn =clsdb.opencon()) { sqlcommand cmd = new sqlcommand(); cmd = createcommand(sql, type, paramlist); cmd.connection = cn; cmd.commandtype = type; cmd.commandtext = sql; cmd.executenonquery(); } you don't assign connection object command when sqlcommand executes query needs open connection. first step search connection property see if has been initialized. property null , erro...

excel - Summing rows condition on two columns -

Image
i'd use array function conditional sum based on 2 columns. given example, each id want calculate sum of value column if column b -1 . id | b | value | ________________________ 1 a1 1 2 2 a2 1 3 3 a3 1 4 4 a3 -1 5 5 a3 -1 1 6 a2 1 5 7 a1 1 1 8 a2 -1 2 the outcome should be: id | value_total | ________________________ 1 a1 1 0 2 a2 1 2 3 a3 1 6 this gives outcome show example data: edit seems have ‘done trick’, explanation: =sumifs syntax sumifs(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...) so in case formula summing columnd values in corresponding row columnb value whatever happens in columnb row containing formula , columnc value -1 . the answer not repeat column unique values of id because 3 distinct ids shown in example and, conveniently, these first 3 , in order.

sql server - Slow SQL 2008 Cursor Performance - Index scan/seek -

Image
i have found interesting "issue" when using ado driver sql server 2008 (or rather when using specific sql cursors created driver). want execute following query: select id, televeid, teldayid, telmobid, qualityflag, weekbegin cef (televeid = '+44xxxx') or (teldayid = '+44xxxxx') or (telmobid = '+44xxxx') order id desc where there (for sake of example) 3 indexed on cef table tuples [id; televeid], [id; teldayid], , [id; telmobid] the query above "translated" driver in following way: declare @p1 int declare @p2 int declare @p5 int set @p5=4 declare @p6 int set @p6=4 declare @p7 int set @p7=-1 exec sp_cursorprepexec @p1 output,@p2 output,null,n'select id, televeid, teldayid, telmobid, qualityflag, weekbegin cef (televeid = ''+44xxxx'') or (teldayid = ''+44xxxx'') or (telmobid = ''+44xxxx'') order id desc',@p5 output,@p6 output,@p7 output exec sp_cursorfetch @p2,2,1,10 the pro...