Selecting Sql Data Source Column Value to Variable (VB.NET) - asp.net

I have a SqlDataSource, defined in the Master Page, that gets the current user permissions for the web application Select * from portal_users where userid = #userid, where portal_users is a view i built with all the data needed. I need to access the contents on the returned row so I can disable/enable site features according to the user permissions. This results in a lot of if blocks across the child pages to do it.
I browsed around forums and I only found issues about assigning those values to controls like i.e. label. Is there a way to access the SqlDataSource from the Master Page, get the row that is returned, select 1 or more column's values and assign them to variables?

Hy
It's not a good idea, use Master Page to share Data Source connections
Read this post to help you:
http://forums.asp.net/t/1188088.aspx?sql+data+source+in+Master+Page
Regards

Related

Pass data between pages ASP.NET

I have two ASP.NET pages.
One of them have a table with some data that came from javascript, each row has a button-link that opens pop-up page. I need to pass the data contained in the selected row to the single row table in pop-up,
what a better way to do that?
If the information are the only identifiers, can move to the other page with parameters in the url, but if they are private or heavy data identifiers is best to store them in the session.
regards

Fill datatable based on user input

I have a SQL db that holds the records for my page. On my page I have a details view I want to populate with records from my db. I can populate the records just fine, I need to be able to populate in records based on a user selection from a drop box?
To clarify, on my main page I have a drop down list with years (ie. 2011, 2010, 2009), and a drop down containing account codes (ie. six-digit numbers). Based on what the user chooses for the year (for example 2010) and the what they choose for the account code (for example 123456) I want to populate the details view (which is on a seperate page) with only those records from 2010 and with the account code 123456??
Far far haven't seen a way to make it work?
To fill the DetailsView based on input from form controls is actually quite straightforward. You're basically using the controls to supply parameter values to plug into the WHERE clause of a select statement.
In essence, you define your SqlDataSource to take Control parameters.
There's also documentation here: http://msdn.microsoft.com/en-us/library/z72eefad.aspx
And an article with screenshots here: http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/using-parameterized-queries-with-the-sqldatasource-vb
If the details view is on a different page, you can do the same thing using QueryString parameters, but that leaves you open to tampering. (People changing the values in thequery string to get at records they shouldn't see.) If tampering isn't an issue with your specific situation - the data isn't sensitive in nature, then it shouldn't be an issue, but its' something to be aware of.

How to show a row from DB and update it value with gridview

My goal is to load a row from db to a webform and let the user update it's value .
The user searches an id (i have a stored procedure for that), how i show that data from the
row nicely in the web page through the dal layer. After the data is shown on the page the user need to update a cell in the row and send it.(the part of updating is not the problem).
in other questions how should the dal method should look and how i integrate it's result in the presentation layer (the aspx webform).
thanks a lot.
p.s.
I've done a little reading but i don't know what exactly to use data object, data row , data table, object data source. i'm little confused by the data bind alternatives.
You have several options and one of them is using ObjectDataSource.
If it is going to be a single record you can use DetailsView or Formview else you use GridView.
Check the tutorials here:
Displaying Data with ObjectDataSource
Data Access Tutorials

How do I use the ASP.NET grid view to instert new records?

Using the ASP.NET grid view. It displays 3 columns with 1 row for each, displaying an integer saved in the database. I would like to have a text input one for each column, so the user can add a new row of integers to the database. (The table only displays the last row updated, that part seems to be working OK)
Here is the code I have that displays data but without the input option I would like.
What is the way this is done in ASP.NET (3.5)? Are there more options in the control or do I need to manually bring in text input controls and give each one manual code to update the database? Any help is appreciated.
Thank You.
Do you know the asp.net website? There are a lot of tutorials, e.g. about data access. You might find the information you need, e.g An Overview of Inserting, Updating, and Deleting Data.
Also check out the ASP.NET Dynamic Data section on the same page.

What is the best approach for this CRUD search page in ASP.NET

I'm building a heavily CRUD based ASP.NET website and I've got to the phase of the project where I'm trying to build a search webpage that shows the user different subsets of a certain important table based on parameters they enter such as dates and different text fields.
I can't use a fixed SQL statement, because depending on whether they search by date or by something else, the SQL would be different, so instead I have been generating a results list using a table web control that starts out invisible and then is filled and set to visible once the user identifies a search they want to make. I used a table control because its easy to create and modify in the code behind, and I was able to make the needed calls to the database and populate that table as required.
However, the second thing I need with this search page, is the ability to allow the user to select a record from the results and then go edit it using the rest of the CRUD based pages on the site. To do that, I created asp:buttons in the table and gave them all different ids and the same event handler. But since I created the buttons dynamically, it seems the event disappears on callback and my scheme fails, so I'm taking a second look at how to do this.
My current code for the events looks like:
tempcell = new TableCell();
Button tempbutton = new Button();
tempbutton.Text = "Go";
tempbutton.ID = "gobutton" + rowN;
tempbutton.Visible = true;
tempbutton.Click += new EventHandler(tempbutton_Click);
tempcell.Controls.Add(tempbutton);
temprow.Cells.Add(tempcell);
My results table is declared like this:
<asp:Table ID="ResultTable" visible="false" runat="server"
GridLines="Both" CellSpacing="8">
</asp:Table>
I'd like to be able to identify which record the user selected, so I can send that info on to another page. And of course, I still need to be able to generate results for several different search criteria. Currently I have date, template and code based searches that lead to different stored procedures and different parameters based on what the user has entered.
Any suggestions on this? It seems like the data grids and repeaters require SQL statements in advance to work properly, so I'm not sure how to use them, but if I could then the item command approach would work with the buttons.
Your event will hook up successfully if the button is recreated in the page load event.
Otherwise, use a GridView. It is the perfect solution for simple CRUD, and you can control it as much as you need.

Resources