I am getting data from MSSQL in ASP.NET using gridview. The data is coming successfully. Only two columns that has HTML in it and have longer text is not showing properly. Each cell ends after 33 characters.
I am getting the data and putting it in LABEL.
The code is as follows inside gridview
<asp:GridView ID="GridView1" runat="server" Width="100%"
Font-Names="Arial" Font-Size="Small"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="IDLessonLearnt" CellPadding="3" CellSpacing="3"
DataSourceID="SqlDataSource1" PageSize="25" ShowFooter="True">
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#25a0da" Font-Names="Arial" Font-Size="14px" Height="30px"></HeaderStyle>
<Columns>
<asp:TemplateField ItemStyle-Width="600px" HeaderText="LESSONS / ISSUES" ItemStyle-HorizontalAlign="left">
<ItemTemplate>
<asp:Label ID="LessonLearned" runat="server" Text ='<%# System.Web.HttpUtility.HtmlEncode(Eval("LessonsIssues"))%>' ></asp:Label>
</ItemTemplate>
<ItemStyle Wrap="true" Width="600" />
<HeaderTemplate>
<asp:TextBox ID="txtLessonLearned" runat="server" onkeyup="filter_LessonLearned(this)" CssClass="texbox_header"
Width="590px" placeholder="LESSONS / ISSUES" Text=""> </asp:TextBox>
</HeaderTemplate>
<ItemStyle HorizontalAlign="left" Width="600px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
I am not using any programming this Gridview and Data source are in .aspx file. All the data is coming fine even html code in database is getting parsed but it is only showing 33 characters of the cell.
Is there any limitation in it? Any suggestions.
Thxn in advance
I found out that the table had varchar(max) but the stored procedure i was using had the length of the columns to 200 which was developed by another developer. I changed to 9000 and now it is working.
Related
Basically, what I want to do is to bind a Linq query to the datasource of a gridview. Here is my code so far :
ddgDossiers.DataSource = (From c In dbConnection.Campaigns.AsQueryable Select c).ToList
ddgDossiers.DataBind()
It compiles and doesn't complain of anything.
<asp:GridView ID="ddgDossiers" runat="server" CellPadding="0" CellSpacing="0" AllowSorting="True"
AutoGenerateColumns="False" EnableViewState="True" AllowPaging="True" PageSize="35"
PagerStyle-HorizontalAlign="Right" PagerStyle-Mode="NumericPages" PagerStyle-Position="TopAndBottom"
BorderWidth="1" GridLines="Both" BorderColor="#000000" CssClass="mGrid" PagerStyle-CssClass="pgr">
<PagerSettings Position="TopAndBottom" />
<Columns>
<asp:TemplateField Visible="false" HeaderText="UniqueID" ItemStyle-HorizontalAlign="left"
HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="1%" HeaderStyle-Width="1%"
HeaderStyle-CssClass="GridTitle" ItemStyle-CssClass="rowReport" SortExpression="UniqueId">
<ItemTemplate>
<asp:Label ID="lblUniqueID" runat="server" Text='<%#Container.DataItem("Campaign.CampaignId").ToString%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The error is pointing on this line :
<asp:Label ID="lblUniqueID" runat="server" Text='<%#Container.DataItem("CampaignId").ToString%>' />
And saying : No default member found for type 'Campaign'.
Is there anything to do with that? Thanks in advance.
change line
Text='<%#Container.DataItem("Campaign.CampaignId").ToString%>'
To
Text='<%# DataBinder.Eval(Container.DataItem, "CampaignId") %>'
I'm trying to make my GridView editable, which will be filled with data from the database.
When my program starts, it will connect to the database and fill the GridView with data. Now I want to edit the data in it, but when I start my program, I get the error "the server tag is not well formed."
Of course I'm looking for some solutions and the most common mistake was, that "" was used instead of '', but I'm already using ''.
Here is my code:
<asp:GridView ID="griddb" runat="server" AutoGenerateEditButton="True"
CellPadding="4" EnableModelValidation="True" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<Columns>
<asp:TemplateField HeaderText="Name" ><ItemTemplate>
<%#Eval("lastname")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="textbox1"runat="server"Text='<%#Eval("lastname")%>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The following snippet is marked as the error:
<asp:TextBox ID="textbox1"runat="server"Text='<%#Eval("lastname")%>'>
Thanks in advance.
I faced the same error.. the server tag is not well formed
But i gave like this
<asp:TextBox ID="textbox1" runat="server" Text="<%#Eval("lastname")%>"></asp:TextBox>
Instead of
<asp:TextBox ID="textbox1" runat="server" Text='<%#Eval("lastname")%>'></asp:TextBox>
If give a text with in Double Quote it will give error like this
The words Server and Text need a space between them in the tag. Actually, most of the tag needs spacing added between the elements. So try this tag instead, note I've added some spaces between elements within the tag.
<asp:TextBox ID="textbox1" runat="server" Text='<%#Eval("lastname")%>'>
I'm trying to display records within my GridView and a few of the cells contain text with carriage returns. However when this text is displayed the carriage returns are gone. Is there an easy way to display carriage returns in a GridView Cell?
I've tried using a TextBox within the cell which works but I then have the scollbars of the TextBox. I'm not too keen on this way either as the textbox may render differently in different browser.
My code is displayed below, I've left my testing in there so you can see all the ways I've tried:
<asp:GridView ID="gridResults" runat="server" AutoGenerateColumns="false" CellSpacing="-1"
CssClass ="stretch separate" GridLines="None" EnableViewState="true">
<HeaderStyle CssClass="header pad" />
<RowStyle CssClass="row pad"/>
<EmptyDataRowStyle CssClass="empty pad" />
<Columns>
<asp:BoundField DataField="Notes" HeaderText="Notes" HtmlEncode="true">
<ItemStyle Width="100" />
</asp:BoundField>
<asp:TemplateField HeaderText="Notes" >
<ItemTemplate>
<asp:Label ID="test" runat="server" Text='<%# Bind("Notes") %>' />
<asp:TextBox ID="textNotes" runat="server" CssClass="right" TextMode="MultiLine" Text='<%# Bind("Notes") %>' BorderStyle="None" />
</ItemTemplate>
<ItemStyle Width="50" CssClass="right" />
</asp:TemplateField>
</Columns>
</asp:GridView>
I'm using ASP.Net 4.0 and c#
Thanks
Try setting the Text attribute of the <asp:Label> to Text='<%# Eval("Notes").ToString().Replace("\n", "<br />") %>'.
In Asp.Net, how to apply text align [left,center,right] in a column, when autogenerate column is true. In every row of gridview the text is displayed in center of the column, i want to display in left side of the column. Thank you.
Try using below syntax if all the columns needs to left aligned
<RowStyle HorizontalAlign="Left"></RowStyle>
Also check these MSDN resource which has various examples for GridView formatting and Code Project article which shows examples for AutoGenerated Columns scenerio.
Sorry, this case will work only when autogeneratedcolumns = "false". See the edit for the autogeneratecolumns="true" If you want to align the header of the column add this to the BoundFiled:
HeaderStyle-HorizontalAlign="Right"
And if you want to align the item of the column add this to the BoundField:
ItemStyle-HorizontalAlign="Right"
EDIT:
Also try this too
Click on the gridView->properties->RowStyle:horizontal-align
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
allowpaging="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<pagerstyle forecolor="Blue"
backcolor="LightBlue"/>
<pagertemplate>
<table width="100%">
<tr>
<td style="width:70%">
<asp:label id="MessageLabel"
forecolor="Blue"
text="Select a page:"
runat="server"/>
<asp:dropdownlist id="PageDropDownList"
autopostback="true"
onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
runat="server"/>
</td>
<td style="width:70%; text-align:right">
<asp:label id="CurrentPageLabel"
forecolor="Blue"
runat="server"/>
</td>
</tr>
</table>
</pagertemplate>
</asp:gridview>
more info on this link
You can define <RowStyle> and <HeaderStyle> elements in your markup.
Example:
<asp:GridView ID="productGridView" Runat="server"
DataSourceID="productsDataSource"
DataKeyNames="ProductID" AutoGenerateColumns="False"
BorderWidth="1px" BackColor="#DEBA84"
CellPadding="3" CellSpacing="2" BorderStyle="None"
BorderColor="#DEBA84">
<FooterStyle ForeColor="#8C4510"
BackColor="#F7DFB5"></FooterStyle>
<PagerStyle ForeColor="#8C4510"
HorizontalAlign="Center"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#A55129"></HeaderStyle>
</asp:GridView>
Put your columns as template fields as per below and give ItemStyle-HorizontalAlign="Left"
<Columns>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="No." ItemStyle-
HorizontalAlign="Left">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
So it will work in all browser.
Suppose I have created a spgridview with the following code.
<SharePoint:SPGridView ID="spgridList" Visible="false" runat="server" AutoGenerateColumns="false"
Width="100%" AllowPaging="true" AllowSorting="true" AllowFiltering="true" PageSize="5"
OnPageIndexChanging="spgridList_PageIndexChanging" HeaderStyle-BackColor="Red"
onrowdatabound="spgridList_RowDataBound" onrowcommand="spgridList_RowCommand">
<PagerStyle CssClass="ms-descriptiontext" />
<HeaderStyle BackColor="Blue" ForeColor="Black" Font-Bold="true" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox CssClass="chkbox" Checked="false" ID="chkField" AutoPostBack="true"
OnCheckedChanged="chkField_CheckedChanged" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkAll_CheckedChanged" />
</HeaderTemplate>
</asp:TemplateField>
</Columns>
</SharePoint:SPGridView>
To persist the checkbox states between pagebacks ,currently i am using session states.It has some draw backs.Now how can I persist the checked states,when the user manually checks all the checkboxes,how can i make a check on the header checkbox?Provide some links
How about emulating it like a select CheckBox but disabling the focus of the row?
Selection of the rows is maintained across pages.
http://www.devexpress.com/Support/Center/p/E1559.aspx