ANAT2403
asked on
update a gridview manually
In ASP.NET 2.0 and C# I have a page with a gridview and SqlDataSource.
In the beginning In SQLDatasource I had the commands for select and update.
I had to create the select manually with sql dataadapter and then bind it to the gridview because there was
aspecial query for it. so the selet command will not be from the sqldatasource. The question is if I can
still use the sqldatasource for the update command or I should also do it manually.
I so I would like to see an example for this.
thankYou
anat
In the beginning In SQLDatasource I had the commands for select and update.
I had to create the select manually with sql dataadapter and then bind it to the gridview because there was
aspecial query for it. so the selet command will not be from the sqldatasource. The question is if I can
still use the sqldatasource for the update command or I should also do it manually.
I so I would like to see an example for this.
thankYou
anat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no you can write whatever command you want.
like this.......
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connCleo %>"
SelectCommand="select chrforename + ' ' + chrsurname from cleo.users where iduser=1"
UpdateCommand="update cleo.usersloggedin set iduser=5">
</asp:SqlDataSource>
like this.......
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connCleo
SelectCommand="select chrforename + ' ' + chrsurname from cleo.users where iduser=1"
UpdateCommand="update cleo.usersloggedin set iduser=5">
</asp:SqlDataSource>
ASKER
I created the sqldatasource with the updatecommand only, then in the code behind created the selectcommand
and put it together with
Sqldatasource1.SelectComma nd = cmd.CommandText;
at the beginning there is no data and only after a GO button is pushed the select is created and the gridview
has values. The problem now is that when I want to update a row, The data in the gridview disappear , I get an empty gridview and only after I push the Go button again I get the option of updating a line and everything comes
back.
What is the problem?
and put it together with
Sqldatasource1.SelectComma
at the beginning there is no data and only after a GO button is pushed the select is created and the gridview
has values. The problem now is that when I want to update a row, The data in the gridview disappear , I get an empty gridview and only after I push the Go button again I get the option of updating a line and everything comes
back.
What is the problem?
Do you want the gridview to bind on load? If so put the databind in page_load event.
As for losing all data, have you got viewstate enabled?
Seve
As for losing all data, have you got viewstate enabled?
Seve
ASKER
I don't what the gridview to bind on load. Only after push the GO button.
Then I give the gridview the sql datasource with a select command but it dissappear afterwords.
How do I enable the viewstate? Isn't in the default choice of a page?
Thanks
Anat
Then I give the gridview the sql datasource with a select command but it dissappear afterwords.
How do I enable the viewstate? Isn't in the default choice of a page?
Thanks
Anat
viewstate is a page and control property. You will see it in the property window of the gridview and datasource.
ASKER
ThankYou
Anat