I used wizard and created sql data source, and binded a gridview to it, this gridview has an edit link, click edit link, it will show Update and Cancel link. It works fine.
I want to know how to connect to the database (the existing sqldatasource) in the code behind and update a record. When user click Edit link, then input some text into a textbox, and then click Update link, it will automatically update database now, but I also want to manually update the status field for this record to Closed. How to do that in the code behind? I need some code. This is C# application. Thank you in advance.
1. I have already had the connection string via SQL Data Source wizard, it is stored in web.config file. How can I call that connection string from code behind? I am not sure if I need re-recreate another connection string in the code.
2. Is there a field in you DB that shows the status of the record?
There is a field named Status in the table.
3. How do you know if the record is closed?
As long as textbox( txtMessage) is not empty and user hits Update button, then we think this record is Closed.
Thank you.
pragmatistMS
In the updating event of the datasource, you basically need to use the FindControl method to find the control that holds the value in question, then you can see if it's empty or not, and set your parameter that way. It would be difficult to provide an exact code snippet without knowing exactly how you're doing things, so this one may require a bit of reading, but I think that should get you started.
Another suggestion, too -- you might get more in-depth responses with higher point offerings. I hope that doesn't come across the wrong way, it's just many folks with knowledge might tend to ignore questions that require more elaborate responses with less than 500-1000 pts.
5281
ASKER
pragmatisMS:
When I was in the school, the professors are so strict, the high score is so hard to get, if you don't pay attention, you can get a C easily. So I am not used to give people a high score now.
Understood, but course, the economics of academia do not map one-to-one with real world software development though. Here,those with questions are effectively "buying" solutions to problems with points as currency, and offering more currency means more motivation. In an academic situation there is no real currency involved -- the professor gets the same reward whether he gives you an A or a D, and use the grade scale as a mechanism to motivate you to work harder. By working students hard they can weed out folks who are unmotivated and might reflect badly on the university if they give them a diploma. It's a very different dynamic.
2. Is there a field in you DB that shows the status of the record?
There is a field named Status in the table.
3. How do you know if the record is closed?
As long as textbox( txtMessage) is not empty and user hits Update button, then we think this record is Closed.
Thank you.