Architecture :: GridView Bound To SqlDataSource?
Sep 19, 2010
I have an aspx page with 2 controls on it - a GridView bound to a SqlDataSource control.Am I correct in thinking this is 2-tier ?If I were to replace the SqlDataSource with an ObjectDataSource, and make the database connections/calls/queries via a class in the App_Code folder, this would be 3-tier, right ?
View 7 Replies
Similar Messages:
Sep 21, 2010
I am trying to populate an (editable) gridview in ASP.NET with a table from SQL. I have a SQLDataSource set up for this. I also need to have this gridview be filterable based on parameters entered in textboxes. I have tried using ControlParameters for this and it works but the problem there is when all textboxes are empty I want it to display all results in the gridview. What it does is display nothing because no entries have parameters that equal "". Is there an easy way to do this that I am missing or is there a better way to go about it other than a SQLDataSource?
View 1 Replies
Jan 31, 2010
I have a sqlDataSource to populate a grdiview ( simple ) . When I set the sql control to a stored proc that has 4 parameters and person a select * from table ignoring the paramaters it doesn't work. No rweturned results.
<table>
<td>
<asp:TextBox ID="vendorid" runat="server" ></asp:TextBox>
<asp:TextBox ID="productid" runat="server" ></asp:TextBox>
<asp:TextBox ID="productdescription" runat="server"></asp:TextBox>
[code]...
View 4 Replies
Jul 5, 2010
I have a ListView control that is bound to an SQLDataSource.
View 6 Replies
Feb 12, 2010
This seems so very simple yet I am very stuck. Following some articles on the web, I came up with an ASP.NET web app page that is all declarative (no code behind) yet when it produces NOTHING I feel so totally stuck about what I've done wrong. Here is the entire little page:
[Code]...
View 9 Replies
Aug 26, 2010
I have a series of dropdownlists on webform in ASP 4.0. The first drop down is filled upon load, and then when a user selects a value from that list, it populates the second dropdown. To accomplish this, I have a SQLdatasource with a parametersource of the first drop-down list control. This works great, except when a user changes their selection from the first drop down. It performs the query, but then adds the list of items to the ones that were already there from the previous selection, instead of replacing it with the new data. Here is the code:
[Code]....
Do I need to do something on selectedindexchanged to somehow "clear out" the previous datasource? I can't find anything about this online, although one person seemed to suggest it was related to using a master page. (which I am using).
View 3 Replies
Jan 13, 2010
If the gridview binds to empty dataset, I need to still show a gridview so that users can ADD more using the textfields in the bottom of the footer template. Since the gridview is empty it won't bind not allowing rendering of the <footer template> I guess I should create a empty dataset if the gridview is empty. How do I check for this and can this be done in GridviewRowEventArgs
View 5 Replies
Oct 23, 2010
I've been working on a webform to pull data from an oracle database v10. I can create a gridview1 with Selection enabled and it will populate with data without a problem. However when I create a second gridview and bind with a control to the first gridview, I get the following error at runtime when I click on one of the Selects.
Exception Details:
Oracle.DataAccess.Client.OracleException: ORA-00936: missing expressionVS 2010.
[code]...
View 4 Replies
Apr 19, 2010
this is my my code snip
[code]....
I put a textbox and a button to page when user click Button , I want to insert a new row to datagrid assume
TextBox.Text = Vivi
when user click Button
first : I use TextBox.Text to DataBase retrieve data for this No (ex: select Name, Tel from student where No = '" TextBox.Text + "'")
and then I want to add this datarow to my DataGrid
I hope I can get result like this
[code]....
How to open a new row to existing GridView? and still keep original data?
View 2 Replies
Feb 9, 2010
I'm having some evils trying to get my GridView control to behave. I have the below code, which successfully displays all the files in the directory. However I require two changes, both of which I am struggling with:
a) Currently the URL you get when clicking on the URL field is [URL] (ie my home directory with the filename). What I require is that the 'Display Text' be the filename only, and the URL be my desired text followed by the filename eg: [URL]
b) I want only to see the files that start with a certain prefix eg "Pay". I can do that with something like: string[] filelist = Directory.GetFiles((@"C:MFData","Pay*.*"); but this doesn't like to bind to my Gridview!
const string DocumentFolderPhysicalPath = (@"C:MFData");
const string DocumentFolderUrl = (@"C:MFData"); [URL]; ; // now it is hardcoded but you could retreive it automatically
HyperLinkField hyperLinkField = new HyperLinkField();
hyperLinkField.DataTextField = "Name";
hyperLinkField.DataNavigateUrlFields = new string[] { "Name" };
//Would like this to work!
//HyperLinkField hyperLinkField2 = new HyperLinkField();
//hyperLinkField2.DataTextField = "Destination";
//hyperLinkField2.DataNavigateUrlFields = new string[] { (@"C:MFData") + "Name" };
GridView1.DataSource = GetDocuments(DocumentFolderPhysicalPath);
GridView1.Columns.Add(hyperLinkField);
GridView1.DataBind();
private System.IO.FileInfo[] GetDocuments(string physicalPath)
{
System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(physicalPath);
if (directory.Exists)
{
return directory.GetFiles();
}
else
{
throw new System.IO.DirectoryNotFoundException(physicalPath);
}
}
View 1 Replies
Jul 13, 2010
I have a repository that contains all of my LINQ queries for this project that I am working on. I am able to get the LINQ results to a DataTable and bind that to a gridview for displaying the data. Now I need to make the gridview sortable. I have set AllowSorting="true" and I have the OnSort event handled in a routine in the codebehind.
View 2 Replies
Nov 23, 2010
here my code-
<asp:BoundField DataField="DayOfTheWeek" HeaderText="Day" ItemStyle-CssClass="Itemstyle"/>
from my collection entity I am getting DayOfTheWeek like 1,2...7. 1 for monday , 2 for tuesday like that. Where should I place condition so that in grid view it would display day name rather than corresponding code.
View 1 Replies
Oct 22, 2010
I have a grid bound to a linqed SP thus:
Session["results"] = db.spGetCaseByNumberOrSurname(txtCaseNum.Text.Trim(), null).ToList();
gvResults.DataSource = Session["results"];
on the sorting of it, i would like to be able to do this..
protected void gvResults_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression;
List<spGetCaseByNumberOrSurnameResult> data = Session["results"] as List<spGetCaseByNumberOrSurnameResult>;
if (sd == SortDirection.Ascending)
{
sd = SortDirection.Descending;
gvResults.DataSource = data.OrderBy(d => d.GetType().GetProperty(sortExpression));
}
else
{
sd = SortDirection.Ascending;
gvResults.DataSource = data.OrderByDescending(d => d.GetType().GetProperty(sortExpression));
}
gvResults.DataBind();
}
sadly that doesnt do any sorting at all..it in fact errors with "The data source does not support server-side data paging."
View 1 Replies
Jan 5, 2011
My GridView is bound to a certain DataSource. Each row only shows 4 of the 8 possible items. Lets say we have name, adress, phone, fax, email, country, province and age. The GridView would only show name, email, country and age, but I want to access the province and adress bound to a row.
I got a custom GridView, with an onclick event which updates an panel (through AJAX) which shows additional information about the selected row.
View 1 Replies
Aug 11, 2010
I have an ASP.NET GridView control in a Web Form. For the sake of simplicity, I will say that this GridView is defined as follows:
[code]...
When each of these rows is bound (a.k.a. during the "myGridView_RowBound" event), I want to get the ID, Name, and Age values. My problem is, I cannot figure out how to get the "ID" value. The reason why is because it is in an invisible field.
View 2 Replies
Sep 21, 2010
I have to set maximum length for bound field in an editable gridview. For this i have used data format string property and also given ApplyFormatInEditMode="true" still it accepts invalid input. The gridview does not have template field, it contains bound fields only. I have written OnRowEditing and RowUpdating events. The dataformat string is DataFormatString="{0:N0}" but it accepts '2352345234523454352345' input also and displays server error while updating in database. I want to spcify maximum length for the textboxes generated dynamically when Edit button is clicked.
View 2 Replies
Sep 28, 2010
I have a gridview which is bound to a DataTable. When I try to sort the gridview, it goes blank. How can I enable sorting this gridview? I know this question has been asked before, but what I'm looking for is an explanation of how to do it. Perhaps with a simple example.
I have read that I need to put some code in the on_sorting and/or on_sorted events, but I don't understand what needs to go there. Again, I want to understand the method of accomplishing this, I don't just want a giant block of code.
View 4 Replies
Dec 24, 2010
i think this maybe an easy one...I have a Gridview, bound to a dataSource with this query:select userid, name, phone from usersI need to change the content of the Name cell to a link, like so:<a href="http://www.domain.com/page.aspx?userid=12345">User's Name</a>
so OnRowDataBound i'm doing this:
e.Row.Cells[1].Text = "<a href="http://www.domain.com/page.aspx?userid=" + e.Row.Cell[0].Text + "">" + e.Row.Cells[1].Text + "</a>";
It all works fine this way. My problem is that i don't want to display the UserId column in the Gridview, but when i attribute it (asp attribute or server-side) Visible="false" to the BoundField UserId, i can't capture it's value to build the Name Cell.
View 3 Replies
Mar 2, 2011
I'm hacking my way through ASP.Net WebForms, coming from VB.Net WinForms. I was hoping the transition would've been more seamless... it is not.
I have a GridView (Paging enabled) bound to a DataTable, filled with Joined tables from an Access 2000 DataBase.
The GridView and DetailsView are bound to the same DataTable.
In the GridView's SelectedIndexChanged Event I have the following:
vb.net Code:
' dtvSelected is the DetailsView' dgvJobTOF is the GridView Me.dtvSelected.PageIndex = Me.dgvJobTOF.SelectedIndex
When the page loads the first item in the GridView is also displayed in the DetailsView.
I've added a "Select" button in the GridView and when it is clicked the Data in the DetailsView remains the same regardless of the selected GridView row.
DataBinding Method:
vb.net Code:
[code]....
View 14 Replies
Apr 30, 2010
I would like the rows of my GridView to have strikethrough based on a bound data value called IsObsolete. I tried to do this:
<RowStyle BackColor="#EFF3FB" Font-Strikeout='<%# Bind('IsObsolete') %>' />
But obviously this doesn't parse. I'd rather not do this in GridView.DataBound().
View 2 Replies
Jul 2, 2010
I got his code for RowDataBound
[Code]....
View 4 Replies
Apr 14, 2010
I have got a simple gridview two bound columns and one template column with a textbox.
I need to get the values of the bound columns is this possible. I need to times the textbox with the bound column value
Now i can get the textbox value using
// var sumInput = null;
// var tempValue = 0.0;
// var retail = 0.0;
// function Load(sender, args) {
// sumInput = sender;
// }
// function Blur(sender, args) {
// sumInput.set_value(tempValue + (sender.get_value()));
// }
// function Focus(sender, args) {
// tempValue = sumInput.get_value() - (sender.get_value());
// }
View 4 Replies
Oct 24, 2011
I've got a grid view on my form that is bound to a data table at run tim. The data table is returned by a function rather than direct from the DB so I can't set the datasource at runtime.
I bind the grid in the page_load event like this:-
Code:
Dim _dt As System.Data.DataTable
_dt = _srvc.GetVinylShutters(0)
_dt.Rows.Add(_dt.NewRow)
grdShutters.DataSource = _dt
grdShutters.DataBind()
(_dt.Rows.Add(_dt.NewRow) is just there to add a blank row in, otherwise I wasn't seeing any columns at all)
I've then got the following snippet which I want to use to hide some underlying columns:-
Code:
For Each col As DataControlField In grdShutters.Columns
Select Case col.HeaderText
Case "OrderID", _
"ShutterID", _
"ModelID", _
[Code] ...
The thing is, wherever I put this it doesn't seem to hide the columns. If I break into the code I can see that grdShutters.Columns.Count equals zero althought I can see that the bound datatable has 38 columns.
I've tried the Page's Load, LoadComplete and PreRenderComplete events as well as the gridview's DataBound, RowDataBound and RowCreated events. I get teh same result in all of them. The grid doesn't actually have any columns until it appears on the screen.
View 7 Replies
Jan 19, 2010
I'm currently using a GridView and I want to set the CssClass for the Row depending on a property of the object that the row is being bound to.I tried the following:
<asp:GridView id="searchResultsGrid" runat="server" AllowPaging="true" PageSize="20" AutoGenerateColumns="false">
<!-- The following line doesn't work because apparently "Code blocks
aren't allowed in this context --> <RowStyle CssClass="<%#IIF(DataBinder.Eval(Container.DataItem,"NeedsAttention","red","") %>
<Columns>
<!--............-->
</Columns>
</asp:GridView>
Now I could simply handle theGridView's RowDataBound event and change the css class of the row there...but I'm trying to keep a clear separation between the UI and the page/business logic layers.
View 1 Replies
Dec 16, 2010
I have a gridview control on a .aspx page. It is a bound control. So basically I didn't have to write any code to pull the data from database and show it on the grid.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStrdatabase %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM order WHERE SETTLEMENT_DT > AS_OF_DT"
</asp:SqlDataSource>
<asp:GridView ID="GridViewMissingCusipNumbers" runat="server"
AllowPaging="True" AllowSorting="True" SkinID="Professional" Font-Name="Verdana"
Font-Size="10pt" Cellpadding="4"
HeaderStyle-BackColor="#444444"
HeaderStyle-ForeColor="White"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" DataKeyNames="BO_SECID"
onrowcommand="GridViewMissingCusipNumbers_RowCommand" Height="285px"
onrowediting="GridViewMissingCusipNumbers_RowEditing"
onrowupdated="GridViewMissingCusipNumbers_RowUpdated"
onrowupdating="GridViewMissingCusipNumbers_RowUpdating" Width="426px"
onrowcancelingedit="GridViewMissingCusipNumbers_RowCancelingEdit">
<Columns>
<asp:BoundField ReadOnly="true" DataField="BO_SECID" HeaderText="BO SECID"
SortExpression="BO_SECID" />
<asp:BoundField DataField="CUSIP" HeaderText="PROXY CUSIP" SortExpression="CUSIP" />
<asp:BoundField DataField="PRICE" HeaderText="PRICE" SortExpression="PRICE" />
<asp:CommandField ShowEditButton="true" />
</Columns>
<HeaderStyle BackColor="#444444" ForeColor="White"></HeaderStyle>
<AlternatingRowStyle BackColor="Silver" BorderColor="Black" />
</asp:GridView>
So far so good. But where is no data is not returned from the database, I want to display something on the page saying "No data returned". But I don't know which gridview control event gets fired so that I can write some code in it to check if the records returned are zero.
View 1 Replies