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%">
Related
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.
On one of my final year project page I have a DetailsView that I am using to update/edit a GridView.
I have a password field that must show the hashed password.
When I am in "edit" or "insert" mode in the DetailsView and inserting a new password in the field (or editing the field) I would like to hash directly the password before showing it in the GridView/DetailsView and of course before inserting/updating it in the DataBase.
My GridView & DetailsView are both in the same UpdatePanel and I am using a ObjectDataSource.
That a partial code:
<asp:DetailsView ID="DetailsViewSingleUsr" runat="server" Height="50px"
Width="125px" DataSourceID="SingleUserObjectDataSource" DataKeyNames="id"
onitemdeleted="DetailsViewSingleUsr_ItemDeleted"
oniteminserted="DetailsViewSingleUsr_ItemInserted"
onitemupdated="DetailsViewSingleUsr_ItemUpdated" AutoGenerateRows="False"
oniteminserting="DetailsViewSingleUsr_ItemInserting">
<Fields>
<asp:TemplateField HeaderText="User ID" InsertVisible="False"
SortExpression="id">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserName" SortExpression="username">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("username") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("username") %>'></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
ErrorMessage="Username may only contain alphanumeric characters"
ValidationExpression="^[a-zA-Z0-9_]*$" SetFocusOnError="True"></asp:RegularExpressionValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="UserName already exist." SetFocusOnError="True" Display="Dynamic"
ControlToValidate="TextBox1" onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("username") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name" SortExpression="firstname">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("firstname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name" SortExpression="lastname">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("lastname") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("lastname") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("lastname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="pass">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("pass") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("pass") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("pass") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Score" SortExpression="currentScore">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("currentScore") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("currentScore") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("currentScore") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Best Score" SortExpression="maxScore">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("maxScore") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("maxScore") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("maxScore") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True"
CommandName="Update" ImageUrl="~/images/update.png" />
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False"
CommandName="Cancel" ImageUrl="~/images/cancel.png" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True"
CommandName="Insert" ImageUrl="~/images/insert.png" />
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False"
CommandName="Cancel" ImageUrl="~/images/cancel.png" />
</InsertItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False"
CommandName="Edit" ImageUrl="~/images/edit.png" />
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False"
CommandName="New" ImageUrl="~/images/new.png"/>
<asp:ImageButton ID="ImageButton3" runat="server" CausesValidation="False"
CommandName="Delete" ImageUrl="~/images/delete.png"/>
</ItemTemplate>
<ControlStyle Height="20px" Width="20px" />
</asp:TemplateField>
</Fields>
</asp:DetailsView>
I am able to access the password textbox in the code behind in the "ItemInserting" Event with that code:
protected void DetailsViewSingleUsr_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
DetailsView myDetailsView = (DetailsView)sender;
if (myDetailsView.CurrentMode == DetailsViewMode.Insert)
{
Label9.Text = ((TextBox)myDetailsView.FindControl("TextBox4")).Text;
}
}
But how can I modify? Am I on the right way? Any suggestions?
Thx a lot guys!
ListViewInsertEventArgs contains property Values, in which you can find all of inserting values, obtained from controls. You may just modify those data. For example
e.Values["password"] = "newpassword";
Thanks! I've finally end up with this code:
protected void DetailsViewSingleUsr_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
e.Values["pass"] = LoginSecurityLogic.Hash_Password_to_MD5(e.Values["pass"].ToString());
}
protected void DetailsViewSingleUsr_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
e.NewValues["pass"] = LoginSecurityLogic.Hash_Password_to_MD5(e.NewValues["pass"].ToString());
}
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>";
}
}
}
I am getting the following "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." error. How can I avoid this error?
This is my code for editing the data from grid view:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Width="950px">
<asp:Label ID="lblMessage" runat="Server" ForeColor="Red"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="2"
DataKeyNames="DOC_id" ForeColor="Black" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
onrowcommand="GridView1_AddRow" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" Height="392px" ShowFooter="True">
<FooterStyle BackColor="Tan" />
<AlternatingRowStyle BackColor="pink" />
<Columns>
<asp:templatefield showheader="False">
<edititemtemplate>
<asp:linkbutton causesvalidation="True" commandname="Update"
id="LinkButton1" runat="server" text="Update"></asp:linkbutton>
<asp:linkbutton causesvalidation="False" commandname="Cancel"
id="LinkButton2" runat="server" text="Cancel"></asp:linkbutton>
</edititemtemplate>
<footertemplate>
<asp:linkbutton commandname="AddNew" id="AddNew" runat="server">Add
New</asp:linkbutton>
</footertemplate>
<itemtemplate>
<asp:linkbutton causesvalidation="False" commandname="Edit" id="LinkButton1"
runat="server" text="Edit"></asp:linkbutton>
</itemtemplate>
</asp:templatefield>
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the
record?')">
<asp:LinkButton ID="lnkB" runat="Server" Text="Delete"
CommandName="Delete"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DOC_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DOC_id") %>'>
</asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox22" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator22" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox22">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DOC_id") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Type">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Dr_Type") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="TextBox1">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox1">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Dr_Type") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Title">
<EditItemTemplate>
<asp:DropDownList ID="TextBox2" runat="server" selectedvalue='<%#
Bind("Dr_Title") %>'>
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
<asp:ListItem>Fr.</asp:ListItem>
<asp:ListItem>Sr.</asp:ListItem>
<asp:ListItem>Rev.</asp:ListItem>
<asp:ListItem>Dr.</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="TextBox2">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="NewTextBox2" runat="server" >
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Ms.</asp:ListItem>
<asp:ListItem>Fr.</asp:ListItem>
<asp:ListItem>Sr.</asp:ListItem>
<asp:ListItem>Rev.</asp:ListItem>
<asp:ListItem>Dr.</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox2">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Dr_Title") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Dr_FirstName")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="*" ControlToValidate="TextBox3">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator3" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox3">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Dr_FirstName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_MiddleName">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Dr_MiddleName")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="*" ControlToValidate="TextBox4">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox4" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator4" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox4">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Dr_MiddleName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Dr_LastName") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ErrorMessage="*" ControlToValidate="TextBox5">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox5" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator5" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox5">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Dr_LastName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Suffix">
<EditItemTemplate>
<asp:DropDownList ID="TextBox6" runat="server" selectedvalue='<%#
Bind("Dr_Suffix") %>'>
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Sr</asp:ListItem>
<asp:ListItem>Jr</asp:ListItem>
<asp:ListItem>III</asp:ListItem>
<asp:ListItem>IV</asp:ListItem>
<asp:ListItem>DMD</asp:ListItem>
<asp:ListItem>DO</asp:ListItem>
<asp:ListItem>DDS</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>PHD</asp:ListItem>
<asp:ListItem>DVM</asp:ListItem>
<asp:ListItem>Esq</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ErrorMessage="*" ControlToValidate="TextBox6">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="NewTextBox6" runat="server">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Sr</asp:ListItem>
<asp:ListItem>Jr</asp:ListItem>
<asp:ListItem>III</asp:ListItem>
<asp:ListItem>IV</asp:ListItem>
<asp:ListItem>DMD</asp:ListItem>
<asp:ListItem>DO</asp:ListItem>
<asp:ListItem>DDS</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>PHD</asp:ListItem>
<asp:ListItem>DVM</asp:ListItem>
<asp:ListItem>Esq</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator6" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox6">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Dr_Suffix") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_Degree">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Dr_Degree") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ErrorMessage="*" ControlToValidate="TextBox7">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox7" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator7" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox7">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Dr_Degree") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_PreferredUsername">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%#
Bind("Dr_PreferredUsername") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ErrorMessage="*" ControlToValidate="TextBox8">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox8" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator8" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox8">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("Dr_PreferredUsername")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_ContactNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Dr_ContactNumber")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ErrorMessage="*" ControlToValidate="TextBox9">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3"
runat="server"
ControlToValidate="TextBox9"
ErrorMessage="Invalid Contact Number....!!" ForeColor="Red"
ValidationExpression="^[9,8,7][0-9]{9}$"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox9" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator9" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox9">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4"
runat="server"
ControlToValidate="NewTextBox9"
ErrorMessage="Invalid Contact Number....!!" ForeColor="Red"
ValidationExpression="^[9,8,7][0-9]{9}$"></asp:RegularExpressionValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("Dr_ContactNumber")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_FaxNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("Dr_FaxNumber")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
ErrorMessage="*" ControlToValidate="TextBox10">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox10" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator10" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox10">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Dr_FaxNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_EmailAddress">
<EditItemTemplate>
<asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("Dr_EmailAddress")
%>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ErrorMessage="*" ControlToValidate="TextBox11">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5"
runat="server"
ControlToValidate="TextBox11" ErrorMessage="Invalid Email ID....!!"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewTextBox11" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator11" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox11">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6"
runat="server"
ControlToValidate="NewTextBox11" ErrorMessage="Invalid Email ID....!!"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("Dr_EmailAddress")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dr_SpecialtyArea">
<EditItemTemplate>
<asp:DropDownList ID="TextBox12" runat="server" selectedvalue='<%#
Bind("Dr_SpecialtyArea") %>'
DataSourceID="SqlDataSource3" DataTextField="Speciality"
DataValueField="Speciality">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
SelectCommand="SELECT [Speciality] FROM [Doc_Speciality]">
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server"
ErrorMessage="*" ControlToValidate="TextBox12">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="NewTextBox12" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Speciality"
DataValueField="Speciality">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
SelectCommand="SELECT [Speciality] FROM [Doc_Speciality]">
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="NewRequiredFieldValidator12" runat="server"
ErrorMessage="*" ControlToValidate="NewTextBox12">
</asp:RequiredFieldValidator>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("Dr_SpecialtyArea")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
</asp:Panel>
<asp:LinkButton ID="AddNew" runat="server" Text="AddNew"
onclientclick="imgbtn_Click" onclick="AddNew_Click"></asp:LinkButton>
</asp:Content>`
Try this solution:
http://w3ka.blogspot.com/2007/09/dropdownlist-in-gridview.html
You have to create a DataBound event for the DropDownLists that use the SqlDataSource and set the SelectedValue there.
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" />