Click here to Skip to main content
15,301,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am building a web usercontrol, the user control has a grid which is bound to a SQLDatasource at runtime.

The grid on usercontrol allows binding to database Table specified by the user at runtime and the columns are generated at runtime.

I have managed to generated the insert,delete,update command and parameters at runtime, but once the page is rendered for some strange reason the SQLDatasource insert,delete,update command becomes blank.

any ideas guys?????

What I have tried:

SqlDSGridDetail.UpdateCommandType = SqlDataSourceCommandType.Text;
SqlDSGridDetail.UpdateCommand = "update table set col =@col where col1 =@col1";

SqlDSGridDetail.InsertCommandType = SqlDataSourceCommandType.Text;
SqlDSGridDetail.InsertCommand = "insert into table(col) values (@col)=@col1";
Richard Deeming 31-Jan-17 9:13am
What triggers the code that's setting the commands?

Depending on when you run it, and whether or not you have viewstate enabled, you might need to re-run the code on each postback.
Ajit78 1-Feb-17 2:54am
Thanks for the reply Richard

The usercontrol has a code behind function "LoadDetails" this is where the sqldatasource is assigned Table name and then linked to a grid, after which I am generating the insert,update,delete command string.
i tried enable and disable the viewstate still same issue.

Does any thing need to be done in the webform I am adding the usercontrol??

Richard Deeming 1-Feb-17 7:48am
So what calls the LoadDetails function? Are you calling it every time the page loads?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900