c# - Using multiple textboxes text to form a JSON string -


i have button store text value of 80 text boxes in winforms c#.

the button looks @ moment

    private void btnsavechanges_click(object sender, eventargs e)     {         //create new connection mongodb database , select database , "table"         var nol = networkopslayer.networkopslayer.createfordirectmongoconnection("mongodb://snipip", "snipdbname", "snip");         //inser document starting selected node name, id, timestamp , entire loan data         nol.insertdoc("{ \"loanname\" : \"" + tvtodolist.selectednode.name + "\", \"agentname\" : \"" + txtagentname.text + "\" }");     } 

this approach work end string long. nol.insertdoc("{long json string of keys , textboxids}") 80 textbox values each json key contained inside string.

i'm wondering if there better way go this? possible still form valid json string looping through each textbox on form , give key relates textbox it's identifiable inside mongodb database?

you can loop through controls pick out names of textboxes , corresponding values this:

list<string> textboxnames = new list<string>(); list<string> textboxvalues = new list<string>();  foreach (var c in this.controls) {     if (c textbox)     {                            textboxnames.add((c textbox).name);         textboxvalues.add((c textbox).text);     } }  

what values :)


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -