grid view data in text box instead of cell - asp.net

I have a web page containing a grid view and need to display the data in the text box on page load instead of cell.
** Grid is read only
** There will not be edit/delete links.
is it possible ?
Thanks in advance.

You can use gridview templates fields, and you will find more about Using TemplateFields in the GridView Control
You can do something like this
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txbType" Text='<%# Eval("fieldName") %>' Enabled="false" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
In here <%# Eval("fieldName") %> -- fieldName should be the value need to be display from your DB

You have to add TemplateFields to the GridView and bind the TextBoxe(s) into ItemTemplate of each TemplateField column.

Related

Textbox losing data within HeaderTemplate on Postback in ASP.Net

I have a ASP.Net GridView and I build the column collection myself. Within the column collection I have a HeaderTemplate and within there I have a textbox which I use to filter the records in the grid.
When I enter text within this textbox and perform an action on the grid which causes a postback (i.e. changing the page) I lose the text within my textbox.
Anybody got any ideas as to why this data is lost?
My ASP code for the header template is below:
<HeaderTemplate>
<asp:Label ID="Label1" Text="Number" runat="server" />
<asp:TextBox ID="textBoxNumberFilter" runat="server" />
<asp:ImageButton ID="buttonFilterNumber" runat="server" OnClick="buttonFilters_Click" />
</HeaderTemplate>
Thanks in advance. I'm using ASP.Net 4.0
I think this might help.
http://www.codeproject.com/Articles/38714/How-To-Perpetuate-Dynamic-Controls-Between-Page-Vi

Interacting with rad grid? How to declare the custom columns?

In web application[asp.net], i am using telerik grid control, i am bind the data to grid when it is autocompletecolumns=true, now i want to bind the data autogeneratecolumns=false how can i place controls like in asp.net grid we use
<columns><asp:Templatefileds><ItemTemplate><asp:label id ="lblid" runat="Server"
Text='<%# Eval("Empid") #> /></ItemTemplage></asp:templae>
Radgrid also have template column like ASP gridview, you can use template columns as:
<MasterTableView ShowFooter="False">
<Columns>
<telerik:GridTemplateColumn UniqueName="TemplateColumn" SortExpression="CompanyName">
<ItemTemplate>
// Your Logic Here
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
Hope this helps.
When the columns are not autocompleted, you must specify them as tags inside your Columns tag. You must specify the attributes for the tags which denote your columns and in the NeedDatasource event you fill your datasource.

SPGridView Filter menu shown separated of LinkButton with templated header

I use Microsoft.SharePoint.WebControls.SPGridView control to write out data.
Filtering is allowed for grid.
Columns contain templated column, it define ItemTemplate and HeaderTemplate:
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:LinkButton ID="linkTitleHeader" runat="server" Text="TitleHeader1"
CommandName="Sort" CommandArgument="Title"></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
some text
</ItemTemplate>
</asp:TemplateField>
</Columns>
It works fine, shows header as link, its performs sorting by click, but filter menu
show on separate row:
i expect that it shows as:
I already try with no result:
Leave Text property empty and define other properties
Set Microsoft.Sharepoint.WebControls.Menu Text programmaticaly after
databind
Set link text by javascript
Have any ideas how to join Menu with LinkButton ? Thanks.
You must also specify the properties of SPGridView : FilterDataFields, FilteredDataSourcePropertyName, FilteredDataSourcePropertyFormat. Maybe this article will help you link

How to display a large amount of data in gridview

I am trying to show a large amount of data in gridview but the problem is that everytime data increase the gridview row size increase automatically.
is there any possible way that the data which is stored in my MS access Database display in multi line instead of one single long line.
If you are populating the GridView using AutoGenerate="true" make if AutoGenerate="false"
Then use asp:TemplateField to populate the GridView.
Now give an ItemStyle-Width and ItemStyle-Wrap.
<asp:TemplateField ItemStyle-Width="50px" ItemStyle-Wrap="true">
<ItemTemplate>
<asp:Label ID="ShipNameLabel" runat="server" Text='<%# Eval("ShipName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
The telerik gridview control supports multi line rows http://www.telerik.com/products/aspnet-ajax/grid.aspx.
However, this does cost. You may try displaying only a few columns, then the user has to click on the row to see the other information in a form view.
Don't understand your question fully but it sounds as a Repeater might work better for you where you have more control of the layout of the rendering.
If it is the amount of rows that are the problem I do recommend to introduce paging to limit amount of row displayed at once.
Update:
1) Set up a CssClass for the GridView itself and include the table-layout:fixed style. This tells the browser that you're going to specify the width of each cell. You may also want to include the overall width of the grid here as I mention in (3).
2) The first row of the table sets the width for each cell, and that's usually the HEADER row, not the item row, so use either HeaderStyle-CssClass or HeaderStyle-Width to set the width of the cell.
3) Make certain the table itself is wide enough to hold all of the cells. I added up all of my cell widths and used that to set the width via the CssClass attribute on the GridView.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns='false'>
<Columns>
<asp:BoundField DataField='Name' />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat='server' ReadOnly="true" BorderStyle="None"
TextMode="MultiLine" Text='<%# Bind("Description") %>'
>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You may have to add some styling to gridview via .skin or css

ASP.NET Setting a DetailsView BoundField value from javascript

I'd like to know if it is possible to set a field of a DetailsView BoundField (in edit mode) from javascript? I can't set an id for the boundfield, so obviously can't use document.getElementById() to get to it, but I was wondering if there's another way to do it?
You could try to create an EditItemTemplate, place a TextBox inside and give it an ID of your choice.
Like this:
<Fields>
<asp:TemplateField HeaderText="Column1">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Fields>
If there is stuff to be bound on the TextBox's Text property you could use Bind() method.
Good Luck.

Resources