Forms Data Controls :: GridView Does Not Show Data?
Nov 11, 2010
ASP code
<asp:RadioButtonList ID ="radio1" AutoPostBack="true" runat="server"
onselectedindexchanged="radio1_SelectedIndexChanged">
<asp:ListItem Text = "Department"></asp:ListItem>
<asp:ListItem Text = "Employee"></asp:ListItem>
<asp:ListItem Text ="Operations"></asp:ListItem>
<asp:ListItem Text="Workcenter"></asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" DataSourceID="LinqDataSource1"
ShowHeaderWhenEmpty="True">
</asp:GridView>
c sharp code
public partial class DataEntry : System.Web.UI.Page
{
TrackingDataContext tracking = new TrackingDataContext();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void radio1_SelectedIndexChanged(object sender, EventArgs e)
{
if (radio1.SelectedValue.Equals("Department"))
{
GridView1.DataSource = tracking.GetDeptartmentNames();
if (GridView1.Rows.Count > 0)
{
GridView1.DataBind();
}
}
}
}
GetDeptartmentNames() is the name of the stored proc, when i execute the stored proc inside the database
I have a customized gridvew i.e. grvResult. There is a textbox and a InsertButton in the footer.
If there is a data populated into gridview it is showing GridView footer and inserting data but if there is no data in gridview then its footer also not visible.
I have tried in two ways to make footer visible but it is showing following error:
Object reference not set to an instance of an object.
I am using an ADO Entity Model for my ms-sql database.
My database has a Resellers table which has ResellerID (primary key, int) and Name columns along with other data.
I also have an Orders table which contains OrderID (primary key, int), OrderDate, ResellerID (foreign key to Resellers.ReselerID).
If I just do a query like:
[Code]....
I am able to reference order.Reseller.Name just fine with no problems.
However I have an EntityDataSource on my page as follows:
[Code]....
Notice the Include="Reseller" attribute in the datasource... I also have a GridView tied to that datasource as follows: I cut some of it off for breavity:
[Code]....
Now what I have listed above will run with no errors, but what I want to do is replace the column that displays "ResellerID" with the equivilant to order.Reseller.Name. In other words I want my grid to display the reseller's name rather than the numeric ID.
I have tried to change the DataField to "Reseller.Name" but that will generate the following error:
A field or property with the name 'Reseller.Name' was not found on the selected data source.
Is there anyway to do this without me writing a custom select statement in my code behind?
What I want to do is to replace number with a name. So if in the Month Column it receives five "1" it changes those 5 "1" to JANUARY.
Is it possible? This is because unfortunately I can only arrange my months by number and not by their name, this because of my queries and tables format, so, I thought maybe I can tell the gridview to change the month number to their relative month name.
I m Using DataList Controll for the time being. But i wana use DridView Controll that should display Data Horizontally. Is it Possible? if Yes then How?
I have data coming from two tables with a foreign key relationship - one User table containing users of the web application, and one Page table containing details about pages visited by each user.I would like to be able to view these data in a gridview or the like on a page. It's easy enough to just show the User table data like so (I'm using the Entity Framework and LINQ):
[Code]....
But how can I show the Page details? I'm not bent on any particular way of showing it, but the only idea I've been able to come up with is to have a dropdown list for each user in a column. But I can't figure out how to get the page data into such a dropdown list. The tables are associated with the primary/foreign key UserID.The closest I've come to finding something similar to this is this for Linq2SQL: http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx , and this using more traditional data access: ttp://www.highoncoding.com/Articles/169_DropDownList_Inside_GridView__Method_1_.aspx . Either way, regardless of data access technology, I can't relate these solutions to my example and get it to work
I want to get data from the database and display it in gridview. The gridview should be editable. Meaning the user can add, edit and delete items/rows in the gridview. Everytime the user adds/updates/deletes an item, the gridview is also updated. However, these changes will only be saved to the database once the Save button is clicked.
I want to show the textbox which is in Gridview, eventhough the Datasource[Table] of the Gridview is empty.The user has to enter some value and save it in the table. My problem, when there is no value in the table, textbox is not shown. I am using Linq, So the Gridview has to bind using Linq list or table The objective of the task:
1. Show the blank textbox when there is no data in the table.
2.A Addnew Buton has to show, If the user clicks the Addnew button, One more textbox has to shown and user can enter the second input.
If I write the following code, teh gridview will no longer show the data
gridview.DataSource = null; gridview.Databound.
My question is , I want to make the same thing with a user control that contain a gridview. when I use the user control in an aspx page, I am able to populate it with data, but when I try to make this code, the Datasource does not show, instead, I see .DV. So I tried this code but then , I do not see DataSource property instead I see DV (DataView), when I put .DV = null, I get an error message that the object is not in existed. any idea how to clear the user control gridview from its data.
I have in my code a gridview that I redirect to excel, it works fine when I have data in the data set. waht I want is to show column headers when there is no data right now what i get is empty sheet.
I have three columns in my GridView. Columns are FileName, FileType and More. More field is a link field. If you click on the link, it should display the data (Created Date:10/03/2010 ) like this.
I am displaying city name in grid view using hyperlink column. Because of large number of city name i want to display it in two or three line and paging
In nested gridview, i am finding some problem, i want to show child Grid headers in Parent Gridview. Can anyone tell me that how it is possible? Its very urgent. Waiting for quick response.
i have a gridview where i want to show data from 3 tables TRANSACTIONS,WATERMARKED_TEXT and WATERMARKED_LOGOS where in TRANSACTIONS i have ids of other two tables as stored as foreign key in TRANSACTIONS....i want to use the foreign keys and retreive images stored in other two tables...
here is the code for the gridview
private void BindGridView() { ConnectionStringSettings set = ConfigurationManager.ConnectionStrings["WATERMARKING"]; String cns = set.ConnectionString; SqlConnection con = new SqlConnection(cns); con.Open(); string sql = "SELECT WATERMARKED_LOGOS.WATERMARKED_IMAGE As Image1, WATERMARKED_TEXT.WATERMARKED_IMAGE As Image2, TRANSACTIONS.TRANS_ID As TRANS_ID, TRANSACTIONS.WLID As WLID,TRANSACTIONS.TID As TID, TRANSACTIONS.CATEGORY As CATEGORY FROM TRANSACTIONS INNER JOIN WATERMARKED_LOGOS ON TRANSACTIONS.WLID = WATERMARKED_LOGOS.WLID INNER JOIN WATERMARKED_TEXT ON TRANSACTIONS.TID = WATERMARKED_TEXT.TID where TRANSACTIONS.USERNAME='" + uName + "'"; SqlDataAdapter da = new SqlDataAdapter(sql, cns); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); con.Close(); }
now when i type something in header Search cell , it shows the data of first page index only , it won't show me data from 2nd page index .. here's my code :
protected void PhasesTempGrid_OnDataBound(object sender, EventArgs e){ GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); for (int i = 0; i < PhasesTempGrid.Columns.Count - 1; i++) { TableHeaderCell cell = new TableHeaderCell(); TextBox txtSearch = new TextBox();
[Code] .....
My gridview is in update panel therefore i did this in .js script :
I know two DataBinds are not necesery, but I'm desperate :P And the stored procedure:
[Code]....
Now the @ID_Greznice = "8,9" should return 3 rows and when debuging, GridView.Rows.Count returns the value 3, but the GridView1 isn't visible in the browser
I have a gridview that I only want to show if the page is a postback. I'm not a very good programmer. show me some VB code that will assist this. I think I want to use a page load event and IF NOT Postback then visible = false for my gridview but I don't know how to write it out...
I have a number of user controls. The inner most one has a gridview along with a button, but the gridview sits inside a panel. When the button is clicked, the panel is suppose to show the gridview, but it doesn't. I have even put a break point on the code behind on the button event, but it doesn't event hit the break point when I click the button again.