multiline text in gridview not working - asp.net

Not giving multiline text in gridview cell
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1" ShowFooter="true" AllowPaging="True" AllowSorting="True"
PageSize="5" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="CategoryID" InsertVisible="False" SortExpression="CategoryID">
<ItemTemplate>
<asp:Label ID="lblCategoryID" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryName" SortExpression="CategoryName">
<EditItemTemplate>
<asp:TextBox ID="txtCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="txtDesc" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

None of the textboxes have TextMode set to Multiline.
Set the TextMode property to Multiline on the textbox that you want to be displayed as textarea.
e.g:
<EditItemTemplate>
<asp:TextBox ID="txtCategoryName" Columns="50" Rows="5" runat="server" TextMode="MultiLine" Text='<%# Bind("CategoryName") %>'></asp:TextBox>
</EditItemTemplate>
EDIT
And to make the label wrap, try adding an ItemStyle to it, like this:
<ItemStyle Wrap="true" Width="200" />

Related

Updating gridview row NOT finding data is gridview row

I have looked for a couple of days now and for some reason I am unable to solve my issue. I have a gridview control and wanting to update the row that is selected. I am trying to populate vidInformaiton class, passes to my stored procedure.
<asp:GridView ID="gvVideos" CssClass="gvVideosClass" runat="server"
AutoGenerateColumns="False" DataKeyNames="CustomerId"
OnRowDataBound="OnRowDataBound" OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit"
OnRowUpdating="OnRowUpdating" OnRowDeleting="OnRowDeleting" EmptyDataText="No records has been added.">
<Columns>
<asp:TemplateField HeaderText="Customer">
<EditItemTemplate>
<asp:TextBox ID="customerId" runat="server" Text='<%# Bind("customerId")%>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcustomerID" runat="server" Text='<%# Bind("customerId")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Fid" ItemStyle-Width="50">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
<input type="hidden" name="vidId" value='<%# Eval("fId")%>' />
</ItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("title") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("title") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("typeContent")%>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("typeContent")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Youtube ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ytid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ytid") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("descvid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("descvid") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("thumbnail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("thumbnail") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="SubmitDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("submitdate") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("submitdate") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkActive" runat="server" Checked='<%# Eval("active")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Categories">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("categories") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("categories") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sort order">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("sortord") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("sortord") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="150"/>
</Columns>
</asp:GridView>
<br />
</div>
My code behind look like this. not sure what I am missing. I can't seem to get the values from the row. I have tried everything, DirectCast, FindControl.
Protected Sub OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim updVid As New VidInformation
Dim updVidRecord As New vidController
Dim row = gvVideos.Rows(e.RowIndex)
updVid.customerId = row.Cells(1).Text.ToString
gvVideos.EditIndex = -1
gvVideos.DataSource = updVidRecord.UpdateVidRecord(updVid)
bindGridview()
End Sub
Converting series of helpful comments to an answer
The correct way to get new values posted to edited GridView row is to use NewValues property of the even args object:
Protected Sub OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
...
Dim updVid As New VidInformation
updVid.customerId = e.NewValues("customerId")
...
End Sub
As to why initial approach did not work. Important thing to realize is that GridView row in question was in edit mode during the previous load of the page. During the post back which edit button triggered new values are posted to the server, but the row is no longer in edit mode, so there are no more edit controls to be found in this row. Thus the method described above is the only by-design way to obtain new values for the row.

ASP.NET GridView not saving when textbox is empty

I have a GridView that is editable with an entitydatasource, if my users want to delete the text in one of the fields they cannot. They can replace the text with a space which then saves, but if the textbox is completely empty the save operation doesn't do anything.
How do I combat this?
Thanks
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=CS3Entities" DefaultContainerName="CS3Entities"
EnableFlattening="False" EnableUpdate="True"
EntitySetName="ProductAlertStatuses"
Where="it.AlertType != '0'"
OrderBy="it.Department DESC, it.AlertType DESC"/>
<br/>
<asp:GridView runat="server" ID="ActionPlanGV"
DataSourceID="EntityDataSource1"
OnDataBound="ActionPlanGV_OnRowDataBound"
CssClass="mGrid visibleGrid"
AutoGenerateColumns="False"
DataKeyNames="ProductStatusID">
<Columns>
<asp:TemplateField SortExpression="Department" ItemStyle-CssClass="center">
<HeaderTemplate>
<asp:Label ID="DepartmentColHeader" ToolTip="Moulding or Finishing Department" runat="server" Text="Dept" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="DepartmentColtxt" runat="server" Text='<%# Eval("Department") %>' />
</ItemTemplate>
<ItemStyle CssClass="center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField SortExpression="AlertType" ItemStyle-CssClass="center">
<HeaderTemplate>
<asp:Label ID="AlertTypeColHeader" ToolTip="Alert Type" runat="server" Text="Alert" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="AlertTypeColtxt" runat="server" Text='<%# ItemDAL.GetAlertStatusColourFromNumber(Eval("AlertType").ToString()) %>' />
</ItemTemplate>
<ItemStyle CssClass="center"></ItemStyle>
</asp:TemplateField>
<%--<asp:BoundField DataField="DateAlertRaised" DataFormatString="{0:d}" HeaderText="Date Alert Raised" ReadOnly="True" SortExpression="DateAlertRaised" />--%>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="ItemIDHeader" ToolTip="Item Code" runat="server" Text="Item" />
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="ItemID"
runat="server"
Text='<%# Eval("ItemID") %>'
NavigateUrl='<%# Url.GetUrl("ViewItem", Eval("ItemID")) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Scrap /Parts" ItemStyle-Width="7%" SortExpression="ActionPlanScrapParts">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" TextMode="MultiLine" Width="75" Height="75" runat="server" Text='<%# Bind("ActionPlanScrapParts") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ActionPlanScrapParts") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Defect Issue / Description" ItemStyle-Width="15%" SortExpression="ActionPlanDefectDescription">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanDefectDescription") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ActionPlanDefectDescription") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Root Cause" ItemStyle-Width="15%" SortExpression="ActionPlanRootCause">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanRootCause") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ActionPlanRootCause") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Corrective Action<div style='font-size:8px;line-height:8px;'>FN16, FN17, FN03, FN05,<br/>Change Note Number</div>-Who? Due By?" ItemStyle-Width="20%" SortExpression="ActionPlanCorrectiveAction">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanCorrectiveAction") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("ActionPlanCorrectiveAction") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Preventative Action<br/>-Who? Due By?" ItemStyle-Width="15%" SortExpression="ActionPlanPreventativeAction">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanPreventativeAction") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("ActionPlanPreventativeAction") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reviewed & Closed" ItemStyle-Width="10%" SortExpression="ActionPlanReviewedClosed">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" TextMode="MultiLine" Width="75" Height="75" runat="server" Text='<%# Bind("ActionPlanReviewedClosed") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("ActionPlanReviewedClosed") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ItemStyle-CssClass="noprint" HeaderStyle-CssClass="noprint">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" Text="Save"/>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel"/>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbEdit2" runat="server" CommandName="Edit" Text="Edit"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
There is one codebehind method, but that doesn't touch the data:
protected void ActionPlanGV_OnRowDataBound(object sender, EventArgs eventArgs)
{
foreach (GridViewRow row in ActionPlanGV.Rows)
{
var alertTypeColtxt = (Label)row.FindControl("AlertTypeColtxt");
if (alertTypeColtxt != null)
{
if (alertTypeColtxt.Text == "Red")
alertTypeColtxt.Text = "<svg width='18' height='18'><circle cx='9' cy='9' r='8' fill='red' /></svg>";
if (alertTypeColtxt.Text == "Amber")
alertTypeColtxt.Text =
"<svg width='15' height='15'><rect x='0' y='0' height='15' width='15' fill='orange' /></svg>";
if (alertTypeColtxt.Text == "Green")
alertTypeColtxt.Text = "<svg width='18' height='18'><circle cx='9' cy='9' r='8' fill='green' /></svg>";
}
}
}

GridView going out of page asp.net

GridView is going out of page... it goes further out in edit mode... here's the code for the gridview :
How do I get it to stay within the page (even in edit mode)...
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateEditButton="True" DataKeyNames="EmployeeID" Visible="False"
Width="900px">
<Columns>
<asp:TemplateField HeaderText="EmployeeID" SortExpression="EmployeeID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("EmployeeID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("EmployeeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DOB" SortExpression="DOB">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("DOB") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("DOB") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ContactNo" SortExpression="ContactNo">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ContactNo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("ContactNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmailID" SortExpression="EmailID">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("EmailID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("EmailID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DesignationID" SortExpression="DesignationID">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("DesignationID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("DesignationID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Designation" SortExpression="Designation">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Designation") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Designation") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department" SortExpression="Department">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Department") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DepartmentID" SortExpression="DepartmentID">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("DepartmentID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("DepartmentID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DOJ" SortExpression="DOJ">
<EditItemTemplate>
<asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("DOJ") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("DOJ") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ReportsTo" SortExpression="ReportsTo">
<EditItemTemplate>
<asp:TextBox ID="TextBox12" runat="server" Text='<%# Bind("ReportsTo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("ReportsTo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here's the screenshot
any suggesstions that might work?
This is what worked:
<div style="width:90%;overflow:auto">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateEditButton="True" DataKeyNames="EmployeeID" Visible="False" style="width:100%;overflow:auto"
HorizontalAlign="Center" >
Thnx...
Set Width="100%" .Dont use pixel .
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateEditButton="True" DataKeyNames="EmployeeID" Visible="False"
Width="100%">

Display text in multiline inside a grid view in asp.net

I am using a grid view in my asp.net application. In one column i need to display description(minimum 5 characters. Maximum 255 characters).i am using a label to hold description in that grid view.
But my problem is that if the description is larger it stretches in the browser and show it in one line. I want to display description in multi line (like a paragraph)
I hope some one help me . the entire grid view code is shown below
<asp:GridView ID="gv_View_Documents" runat="server" AllowSorting="true" DataKeyNames="DocumentName,Description" SkinID="customGridview" AutoGenerateColumns="false" OnSorting="gv_View_Documents_Sorting" OnRowCancelingEdit="gv_View_Documents_RowCancelingEdit" OnRowCommand="gv_View_Documents_RowCommand"
OnRowEditing="gv_View_Documents_RowEditing" OnRowUpdating="gv_View_Documents_RowUpdating" >
<Columns>
<asp:TemplateField HeaderText="Document Name" HeaderStyle-Width="200" HeaderStyle-CssClass="GridHeaderStyle" SortExpression="DocumentName" >
<ItemTemplate>
<asp:LinkButton CommandName="ViewDocument" CssClass="GridHeaderStyle" ID="hlnk_View_Document" runat="server" CommandArgument='<%# Bind("DocumentName") %>' Text='<%# Bind("DocumentName") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="200" HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lbl_gv_DocumentDescription" runat="server" Text='<%# Bind("Description") %>' ></asp:Label></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_gv_EditDescription" MaxLength="250" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="50" HeaderStyle-CssClass="GridHeaderStyle" ShowHeader="False" >
<EditItemTemplate>
<asp:LinkButton ID="Bttn_Update_Description" ForeColor=" #555555" runat="server" CausesValidation="False"
CommandName="Update" Text="Update"></asp:LinkButton> <asp:LinkButton ID="Bttn_Cancel_Settings" ForeColor=" #555555" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton></EditItemTemplate><ItemTemplate>
<asp:LinkButton ID="Bttn_Edit_Description" ForeColor=" #555555" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit" ></asp:LinkButton></ItemTemplate><ControlStyle CssClass="edit" />
</asp:TemplateField>
</Columns>
</asp:GridView>
try this... working properly...for wrapping text in Gridview
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Attributes.Add("style", "word-break:break-all;word-wrap:break-word;width:100px");
}
}
}
Sometimes ItemStyle Wrap="true" doesn't work. To be certain your text wraps, surround the Label in a and set a width on the surrounding div.
EDIT
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="<%# Eval("ID") %>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<div style="width:100px;">
<asp:Label ID="Label2" runat="server" Text="<%# Eval("Name") %>"></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text="<%# Eval("Age") %>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
You can set the ItemStyle of the TemplateField to true like this:
<ItemStyle Wrap="true" Width="100px" />
Complete gridview code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle Wrap="true" Width="100px" />
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Age") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Screenshot:
Try like this by applying the css class
.paraGraphtext
{
white-space: pre-wrap;
}
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="<%# Eval("ID") %>" CssClass="paraGraphtext"></asp:Label>
</ItemTemplate>

wcCategory.ascx file use in Gridview or detailsView cell

Work on Asp.Net vs 08 C#,use northwind database . I want wcCategory.ascx file use on gridview cell
Below in my wcCategory.ascx file
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:PopupControlExtender ID="TextBox1_PopupControlExtender" runat="server"
DynamicServicePath="" Enabled="True" ExtenderControlID="" PopupControlID="pnlPopeUp"
TargetControlID="TextBox1">
</cc1:PopupControlExtender>
<asp:Panel ID="pnlPopeUp" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CategoryID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="CategoryID" InsertVisible="False"
SortExpression="CategoryID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CategoryID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCategoryID" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName"
SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Bellow is my .aspx file
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="SqlDataSource2">
<Columns>
<asp:TemplateField HeaderText="ProductID" InsertVisible="False"
SortExpression="ProductID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProductName" SortExpression="ProductName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SupplierID" SortExpression="SupplierID">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("SupplierID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("SupplierID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("CategoryID") %>'></asp:TextBox>
<br />
<br />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QuantityPerUnit"
SortExpression="QuantityPerUnit">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("QuantityPerUnit") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("QuantityPerUnit") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [CategoryID], [QuantityPerUnit] FROM [Products]">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
I want my .ascx file use on gridview Category cell
Use a placeholder and on rowdatabound use findcontrol to find the placeholder and use loadcontrol to add your usercontrol to the controls collection of the placeholder. Does that help?

Resources