well I'm so new to ASP.NET I've been working on this project for about two weeks now, but I can't get a GridView with an objectdatasource to show when webpage loads, I can see all columns in design time.
The method returns a List and in design time I can see all columns with the right column name but when loading the service and the webpage afterwards nothing shows up. Any help will be appreciated. Regards to all readers.
The method receives a string value I've set a default to 'q'.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="Contraseña" HeaderText="Contraseña"
SortExpression="Contraseña" />
<asp:BoundField DataField="Id_User" HeaderText="Id_User"
SortExpression="Id_User" />
<asp:BoundField DataField="Nombre" HeaderText="Nombre"
SortExpression="Nombre" />
<asp:BoundField DataField="Tipo" HeaderText="Tipo" SortExpression="Tipo" />
<asp:BoundField DataField="Usuario" HeaderText="Usuario"
SortExpression="Usuario" />
</Columns>
</asp:GridView>
Add the following to your GridView:
<asp:GridView ID="GridView1" runat="server"
EmptyDataText="DOH! No Data!"
ShowHeaderWhenEmpty="True"
The code looks fine. You don't actually need to call databind() with Data Source Control, instead perhaps you need to check the return value in SelectMethod of objectdatasource.
Related
I've set up an .aspx gridview that shows data from an SQL database based on the user selecting the parameter in a drop-down list.
What I'd like to achieve is that the gridview is empty before the user has made a selection. Is this possible?
There will always be data in the database, so the question is NOT about what to display when there are no rows to show.
Thanks in advance for any assistance!
//Eva-Lotta
ASP.Net 4.0 added the boolean ShowHeaderWhenEmpty property.
<asp:GridView runat="server" ID="GridView1" ShowHeaderWhenEmpty="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="First Name" DataField="FirstName" />
<asp:BoundField HeaderText="Last Name" DataField="LastName" />
</Columns>
</asp:GridView>
The headers will not appear unless DataBind() is called with something other than null.
GridView1.DataSource = New List(Of String)
GridView1.DataBind()
I've solved it in a really simple way! I set gridview visible to false on page load, and true when the user clicked a button. Sometimes it's much easier than expected.
I have a grid view, in which I have 1 column as template field, while other 8 columns are dynamically created.
This template field has a checkbox, while trying to retrieve this checkbox in code-behind file, we get it as null.
When columns are not dynamically created, the checkbox is pretty fine and has a value in code behind.
Below is my code:
<asp:GridView ID="gridResultSet" runat="server" AutoGenerateColumns="false" AllowSorting="true"
OnRowCreated="GridResultSet_RowCreated" OnLoad="GridResultSet_Load" CssClass="reportGrid"
CellPadding="4" OnSorting="GridResultSet_Sorting" OnRowDataBound="GridResultSet_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Reclass">
<ItemTemplate>
<acesec:CheckBox ID="chkReclass" CssClass="CheckBoxListStyle" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="gridrow" />
<AlternatingRowStyle CssClass="gridrow" />
<HeaderStyle CssClass="gridheader" />
</asp:GridView>
System.Web.UI.WebControls.CheckBox chbReclass = gridResultSet.Rows[i].FindControl("chkReclass") as System.Web.UI.WebControls.CheckBox;
Do I need to check something in order to access a template field while creation of dynamic columns?
Any body faced same kind of situation?
Pointers will be highly appreciated.
Regards
Im a newbie in asp.net and im about to do a edit page for my news and announcement page.
This is my sample code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="news_id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="news_id" HeaderText="news_id" InsertVisible="False"
ReadOnly="True" SortExpression="news_id" />
<asp:BoundField DataField="news" HeaderText="news" SortExpression="news" />
<asp:BoundField DataField="news_date" HeaderText="news_date"
SortExpression="news_date" />
<asp:BoundField DataField="news_data" HeaderText="news_data"
SortExpression="news_data" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TDBSConnectionString %>"
SelectCommand="SELECT [news_id], [news], [news_date], [news_data] FROM [ibsi.news]">
</asp:SqlDataSource>
I put the data into a gridview to show all the data from the database.
how can i use this dataview to edit my content or can what can i use in the toolbar to create one edit module.
The link http://msdn.microsoft.com/en-us/library/ms972948.aspx might be able to help you out.
The ASP.NET GridView allows for a row of data to be edited by setting the EditIndex property of the GridView, placing the entire row in edit mode....
To implement this,go throught following article of codeproject:
http://www.codeproject.com/Articles/18136/Edit-Individual-GridView-Cells-in-ASP-NET
I have a gridview that I populate based on a query to a db. I'm trying to add sorting on my gridview but I cannot make my column headers clickable. I have allow sorting set to true, and I have my OnSorting event set. My columns are of a few different types. I know the code I need to have in my code behind, but I cannot click on the headers for some reason. Any help on what I'm missing would be appreciated.
<asp:GridView ID="Grid1" runat="server"
AutoGenerateColumns="False"
OnSelectedIndexChanging="Selected_Row_Changing"
DataKeyNames="ApplicationId"
AllowPaging="True"
OnPageIndexChanging="Grid1_PageIndexChanging"
AllowSorting="True"
OnSorting="Grid1_Sorting"
OnRowCreated="OnRowCreated"
OnRowCommand="Grid1_RowCommand"
OnRowDataBound="Grid1_RowDataBound">
<Columns>
<asp:templatefield ...>
<itemtemplate>
<asp:linkbutton .../>
</itemtemplate>
</asp:templatefield>
<asp:BoundField ... />
<asp:HyperLinkField ... />
<asp:ButtonField ... />
</Columns>
</asp:GridView>
You don't have set the SortExpression, have you?
For example:
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"
headerstyle-wrap="false"
sortexpression="CompanyName"/>
Make sure you're not setting the Header Template but rather set the HeaderText attribute for the TemplateField
I'm currently evaluating some RAD controls from Telerik, just right now I'm experimenting with the RadGrid.
So I have my grid control and enabled client-side binding for having Ajax support. I created an appropriate WCF webservice for fetching the data etc. Everything works really good, including paging etc. Now I wanted to have a button column for deleting some items. I registered the OnItemCommand event of the grid and implemented it accordingly on the server-side. My ASPx code looks like this:
<telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" GridLines="None"
OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView DataKeyNames="Id" ClientDataKeyNames="Id">
<Columns>
<telerik:GridBoundColumn DataField="Firstname" HeaderText="Firstname" DataType="System.String">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Lastname" HeaderText="Lastname" DataType="System.String">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Age" HeaderText="Age" DataType="System.Int32">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
ButtonType="ImageButton">
</telerik:GridButtonColumn>
</Columns>
<PagerStyle Mode="Slider" />
</MasterTableView>
<ClientSettings>
<DataBinding SelectMethod="GetSampleData" Location="Webservice/GridData.svc" SortParameterType="String">
</DataBinding>
</ClientSettings>
</telerik:RadGrid>
However when clicking on the appropriate button on a grid row the event isn't fired, basically no postback to the server is being done. A solution I found is to add the "EnablePostBackOnRowClick=true" to the ClientSettings, but this would cause a postback on each click on a row, which is not really desired.
Is there a better way to realizing this or does anybody have a hint what could be the problem??
Thx
As far as it seems this is not possible given the answer from the Telerik forum.
you need to handle the client "OnCommand" event, or more appropriately use the client "RowDataBound" command. In the RowDataBound command you can find your rad button and attach an event to it.
The only other way to do this is to handle the client "onclicking" event from the button itself.
Example of binding to the OnCommand and Row DataBound:
<ClientSettings>
<ClientEvents OnCommand="Grid_Command" OnRowDataBound="Grid_RowDataBound" />
</ClientSettings>
then in your javascript wrapped in a rad code block have the following methods:
<script type="javascript">
function Grid_RowDataBound(sender, args) {
var item = args.get_item();
var data = args.get_dataItem();
var btn = $find('DeleteColumn');
btn.add_clicking(delegate); // where delegate is the function you provide for the click
// ... //
}
`
I realize this is ancient, but it still shows up high in Google results.
There is now a solution to this, maybe others as well...
You can achieve a postback by using a template column
<telerik:GridTemplateColumn UniqueName="myuniquename">
<ItemTemplate>
<telerik:RadButton ID="RadButton1" runat="server" ButtonType="StandardButton" AutoPostBack="true" CommandName="MyCommand" UseSubmitBehavior="false" Text="Button Text" />
</ItemTemplate>
</telerik:GridTemplateColumn>
Although I'm not sure if you need the "UseSubmitBehavior" property.
I had the same problem with telerik controls. I solved this problem by recreating the Control from zero with a new name, then rebuilding my structure.
Hope it helps
RegisterWithScriptManager="false" this may work as well..