What should I do to fix this? html inside a asp:button need a fix to be displayed, I use this method (it works unless I do click on the header of any column to sort the gridview):
private void FixGlyph(PlaceHolder ph, Button btn, string iconClass, string customLabelStye = "")
{
if (btn.Visible)
{
var g = new HtmlGenericControl();
g.ID = "labelFor_" + btn.ID;
g.TagName = "label";
g.Attributes.Add("for", btn.ClientID);
g.Attributes.Add("class", "" + btn.CssClass + "");
if (customLabelStye != "")
{
g.Attributes.Add("style", customLabelStye);
}
g.InnerHtml = "<i class='" + iconClass + "'></i> " + btn.Text;
ph.Controls.Add(g);
btn.Attributes.Add("style", "display:none;");
}
}
my gridview is this:
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" AllowPaging="True" AutoGenerateColumns="false" DataSourceID="AccessDataSource1" DataKeyNames="FICHA" runat="server" GridLines="None" OnSorted="GridViewFix" AllowSorting="true" CssClass="table table-hover table-striped" ShowFooter="true" PagerStyle-CssClass="bs-pagination text-center">
<Columns>
<%-- Ficha del empleado --%>
<asp:TemplateField HeaderText="Ficha" SortExpression="FICHA">
<ItemTemplate>
<asp:Label ID="lblFicha" Text='<%# Eval("FICHA") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- columna de eliminar --%>
<asp:TemplateField HeaderText="<span class='glyphicon glyphicon-remove'></span>">
<ItemStyle Width="20" />
<ItemTemplate>
<asp:PlaceHolder ID="delPh" runat="server"></asp:PlaceHolder>
<asp:Button ID="delBtn" CssClass="btn btn-link " data-toggle="modal" ToolTip="Modify" data-target="#deleteModal" runat="server" autopostback="false" OnClick="delBtn_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
my Page_Load is like this
protected void Page_Load(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
Button dbtn = row.FindControl("delBtn") as Button;
PlaceHolder dPH = row.FindControl("delPh") as PlaceHolder;
FixGlyph(dPH, dbtn, "glyphicon glyphicon-remove", "padding:0 !important;");
}
}
and I even tried to use onSorted event for the gridview:
protected void GridViewFix(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
Button dbtn = row.FindControl("delBtn") as Button;
PlaceHolder dPH = row.FindControl("delPh") as PlaceHolder;
FixGlyph(dPH, dbtn, "glyphicon glyphicon-remove", "padding:0 !important;");
}
}
which gets trigged, aparently finds the controls and fix the labels but... then something happend after GridViewFix and reloads the components, again without the glyphicons
I would put your code to add the glyphs in the Page_PreRender method. It's possible that after page_load the Gridview has an event that is firing and recreating the button controls.
well, the question wasn't completly clear.. buttons have data-toggle and data-target atributes which LinkButtons don't and that's why wanted them so bad. I Needed to open a modal at the same time I triggered an event on code behind. so this fix the issue: Just trigger the modal yourself with javascript.
<asp:LinkButton ID="AddAreaBtn" runat="server" autopostback="false" OnClientClick="javascript:$('#BorrarAreaModal').modal('show');" OnClick="BorraArea_Click">
<i aria-hidden="true" class="glyphicon glyphicon-remove"></i>
</asp:LinkButton>
Related
I would like the select rowdatabound not to included the first colunm. The reason for it is when i click on expand the datagridview the page refreshes causing the datagridview row to collapse again.
Here is a image of my table I have circuled in red the column I would like to remove from the rowdatabound.
Here is my code for OnRowDataBound
protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvInventario, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Haga clic para seleccionar esta fila.";
}
}
And here is my aspx code:
<asp:GridView ID="gvInventario" runat="server" AutoGenerateColumns="false" AllowSorting="true" ShowFooter="false" DataKeyNames="componente_id, ubicacion_id"
ShowHeaderWhenEmpty="true" AllowPaging="True" OnPageIndexChanging="gridView_PageIndexChanging" OnRowDataBound = "OnRowDataBound" OnSelectedIndexChanged = "OnSelectedIndexChanged"
CellPadding="3" AllowColumResize="True" onsorting="grdDetails_Sorting" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate >
<a href="JavaScript:divexpandcollapse('div<%# Eval("componente_id") %>');" >
<img id="imgdiv<%# Eval("componente_id") %>" width="9px" border="0" src="../images/plus.gif"
alt="" /></a>
</ItemTemplate>
<ItemStyle Width="20px" VerticalAlign="Middle"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Min" SortExpression="cantidad_mini">
<ItemTemplate>
<asp:Label Text='<%# Eval("cantidad_mini") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQuantityMin" Text='<%# Eval("cantidad_mini") %>' runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I would like the first column not to be included in rowdatabound.
Instead of adding the onclick to a row you could add it to each cell individually and skip the first cell.
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvInventario, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Haga clic para seleccionar esta fila.";
}
}
Or add a class name tot the first cell in the RowDataBound or ItemStyle-CssClass in the aspx.
e.Row.Cells[0].Attributes["class"] = "noClick";
Then use jquery to prevent the clicking.
$('.noClick').click(function (e) {
e.stopPropagation();
});
I have a gridview on an asp.net page with two link buttons - one for viewing a pdf and one for downloading. When you click View a pdf viewer is displayed in a literal control. This works fine. But I have paging enabled for my gridview and when I click the paging links the pdf display refreshes, meaning it will reload the last pdf viewed. I'm guessing it has something to do with postback but can't figure out a solution.
<div id="wpaLinks" style="height: 118px;">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="gvWPAs" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="3" CssClass="Grid" AlternatingRowStyle-CssClass="alt"
PagerStyle-CssClass="pgr" EmptyDataText="No Records Found" OnPageIndexChanging="gvWPAs_PageIndexChanging"> <%--OnRowDataBound="gvWPAs_RowDataBound"--%>
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:BoundField DataField="fileDescription" HeaderText="File Description" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="lnkView" runat="server" Text="View" OnClick="View" CommandArgument='<%# Eval("relPath") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("relPath") %>' runat="server" OnClick="DownloadFile"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" PageButtonCount="4" />
<PagerStyle CssClass="pgr" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Literal ID="ltEmbed" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
And the code-behind is....
protected void gvWPAs_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvWPAs.PageIndex = e.NewPageIndex;
var ctyID = CountyList.SelectedValue;
var twnID = TwnList.SelectedValue;
var rngID = RngList.SelectedValue;
if (ctyID != "0" & twnID == "0" & rngID == "0") // County only
{
dsGetCtyWPAs.SelectParameters["ctyID"].DefaultValue = ctyID;
DataView dvCtyWpa = (DataView)dsGetCtyWPAs.Select(DataSourceSelectArguments.Empty);
//DataTable dtCtyWpa = dvCtyWpa.ToTable();
gvWPAs.DataSource = dvCtyWpa;
gvWPAs.DataBind();
this.RegisterPostBackControl();
}
}
protected void View(object sender, EventArgs e)
{
string pdfIdentifier = (sender as LinkButton).CommandArgument;
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"650px\" height=\"850px\">";
embed += "If you are unable to view file, you can download from here";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
ltEmbed.Text = string.Format(embed, ResolveUrl("~/PdfHandler.ashx?pdfPath="), "WpaFiles/" + pdfIdentifier);
}
protected void DownloadFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
string fileName = Path.GetFileName(filePath);
Downloader.Download(fileName, "WpaFiles/" + filePath);
}
The reason your code re-displays the pdf is due to the second UpdatePanel not being updated/cleared.
While controls embedded in an UpdatePanel still cause the full page lifecycle to happen - the nice thing about them is that they only transmit back the changes. So when you are changing a page in the first UpdatePanel, you're not clearing the embed code in the second. This may or may not desired.
On page change you need to clear the embed code in the second updatepanel and make sure that panel gets updated
I set the UpdateMode to Conditional on UpdatePanel3
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Literal ID="ltEmbed" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Then added UpdatePanel3.Update() to....
protected void View(object sender, EventArgs e)
{
string pdfIdentifier = (sender as LinkButton).CommandArgument;
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"650px\" height=\"850px\">";
embed += "If you are unable to view file, you can download from here";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
ltEmbed.Text = string.Format(embed, ResolveUrl("~/PdfHandler.ashx?pdfPath="), "WpaFiles/" + pdfIdentifier);
UpdatePanel3.Update();
}
I have the following gridview and "loadingbar" div:
<asp:GridView ID="importLogGV"
AutoGenerateColumns="false"
DataKeyNames="id"
OnRowDeleting="DeleteStuff"
runat="server"
CssClass="searchListGridView">
<Columns>
<asp:BoundField HeaderText="ID" DataField="id">
[...]
<asp:TemplateField ItemStyle-Width="120">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" CommandName="Delete" Text='Delete' runat="server"
OnClientClick="return confirm('Really delete?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="deleting" style="text-align: center" Visible="False" runat="server"
ClientIDMode="Static">Delete in progress...<br />
<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/ajax-loadingbar.gif"/>
</div>
While the eventhandler "DeleteStuff" runs (it does lots of database things than can take up to 10 seconds) in code behind I need to show the "deleting" div, and when the eventhandler finishes it need to hide the div again.
Here's my eventhandler for the delete in codebehind:
protected void DeleteStuff(object sender, GridViewDeleteEventArgs e)
{
deleting.Visible = true;
System.Threading.Thread.Sleep(5000);
deleting.Visible = false;
}
I've tried using style:display instead of the visible attribute, I've tried using a asp:panel instead of a div, but whatever I do, the eventhandler runs but the div is never shown while it runs.
I thought of showing the div with javascript when the user clicks the delete button, but how would I be able to hide it again then after the DeleteStuff process finishes?
Whenever you click the button to delete, a submit request is sent to the server and your page starts to refresh. The page will be re-rendered after the method on the server finishes execution. So whatever you do inside your method, the last effect will retain. If you want to show busy text on the browser, ajax is the way; you will have to use update panels. Try this:
The javascript:
<script type="text/javascript">
function showDeleteConfirm()
{
var isSure = confirm('Really delete?');
if(isSure)
{
document.getElementById("deleting").style['display'] = 'block';
}
}
</script>
aspx markup:
<asp:UpdatePanel id="up1" runat="server">
<ContentTemplate>
<asp:GridView ID="importLogGV"
AutoGenerateColumns="false"
DataKeyNames="id"
OnRowDeleting="DeleteStuff"
runat="server"
CssClass="searchListGridView">
<Columns>
<asp:BoundField HeaderText="ID" DataField="id">
[...]
<asp:TemplateField ItemStyle-Width="120">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" CommandName="Delete" Text='Delete' runat="server"
OnClientClick="return showDeleteConfirm();" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="deleting" style="text-align: center" style="display:none" runat="server"
ClientIDMode="Static">Delete in progress...<br />
<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/ajax-loadingbar.gif"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
protected void DeleteStuff(object sender, GridViewDeleteEventArgs e)
{
//... Real task here
System.Threading.Thread.Sleep(5000);
deleteing.Style['display'] = 'none';
}
By the way, you need to add a ScriptManager on the page.
Have you tried:
protected void DeleteStuff(object sender, GridViewDeleteEventArgs e)
{
if (CheckAccess())
{
deleting.Visible = true;
System.Threading.Thread.Sleep(5000);
deleting.Visible = false;
}
else
{
Dispatcher.BeginInvoke((Action) (() => DeleteStuff(sender, e)));
}
}
Btw, you should probably use a Timer instead of Thread.Sleep(5000).
As i was written in the title, the problem is very funny :
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id_Newsletter" HeaderStyle-BackColor="Black"
HeaderStyle-ForeColor="White" RowStyle-BackColor="DarkGray" AlternatingRowStyle-BackColor="LightGray" PageSize="6" AllowPaging="true"
AllowSorting="true" ShowHeaderWhenEmpty="true" EmptyDataText="La tabella non contiene dati" EnableViewState="true" RowStyle-Wrap="true"
PagerStyle-HorizontalAlign="Left" PagerStyle-BorderWidth="0" BorderWidth="0" OnRowCommand="GridView_RowCommand"
OnRowCancelingEdit="GridView_RowCancelingEdit" OnRowUpdating="GridView_RowUpdating" OnRowDeleting="GridView_RowDeleting"
OnPageIndexChanging="GridView_PageIndexChanging" OnSorting="GridView_Sorting" OnRowEditing="GridView_RowEditing" CssClass="NewsletterManager_GridView" >
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Indirizzo Email" HeaderStyle-Width="275" SortExpression="emailNewsletter">
<ItemTemplate>
<asp:Label ID="lbl_emailNewsletter" runat="server" Text='<%# Eval("emailNewsletter") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lbl_emailNewsletter" runat="server" Text='<%# Eval("emailNewsletter") %>' Visible="false" ></asp:Label>
<asp:TextBox ID="txt_emailNewsletter" runat="server" Text='<%# Bind("emailNewsletter") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Azioni" HeaderStyle-Width="100">
<EditItemTemplate>
<asp:ImageButton ID="Img_Aggiorna" runat="server" CommandName="Update" ImageUrl="~/images/GridIcon/update.png" ToolTip="Aggiorna" />
<asp:ImageButton ID="Img_Annulla" runat="server" CommandName="Cancel" ImageUrl="~/images/GridIcon/undo.png" ToolTip="Annulla" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="Img_Modifica" runat="server" CommandName="Edit" ImageUrl="~/images/GridIcon/edit.png" ToolTip="Modifica" />
<asp:ImageButton ID="Img_Cancella" runat="server" CommandName="Delete" ImageUrl="~/images/GridIcon/delete.png" OnClientClick="return confirm('Sei sicuro di voler cancellare l\'email?');" ToolTip="cancella" />
</ItemTemplate>
</asp:TemplateField>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
LoadGridView(GridView1, -1, 0);
lbl_result.Text = String.Empty;
}
protected void GridView_RowEditing(Object sender, GridViewEditEventArgs e)
{
LoadGridView(((GridView)sender), e.NewEditIndex, ((GridView)sender).PageIndex);
}
protected void GridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
NewsLetterBL newsBl = new NewsLetterBL();
String oldmail = ((Label)((GridView)sender).Rows[e.RowIndex].FindControl("lbl_emailNewsletter")).Text;
String newmail = ((TextBox)((GridView)sender).Rows[e.RowIndex].FindControl("txt_emailNewsletter")).Text;
if (newsBl.ModifyWrongEmail(oldmail, newmail))
lbl_result.Text = "Modify Done";
else lbl_result.Text = newsBl.LastMessage;
LoadGridView(((GridView)sender), -1, ((GridView)sender).PageIndex);
}
protected void LoadGridView(GridView GV, int EditIndex, int PageIndex)
{
NewsLetterBL newsBl = new NewsLetterBL();
DataView dw = new DataView(newsBl.getFullNewsletter());
String SortExpression = GV.ID.ToString() + "_SortExpression";
if (ViewState[SortExpression] != null) dw.Sort = (String)ViewState[SortExpression];
GV.DataSource = dw;
GV.PageIndex = PageIndex;
GV.EditIndex = EditIndex;
GV.DataBind();
}
When I try to access to the txt_emailNewsletter control into the row in edit mode from the GridView_RowUpdating that handle the OnRowUpdating event of the GridView1, the element throws a NullReferenceException, but the lbl_emailNewsletter control can be founded.
The labels into ItemTemplate and EditItemTemplate have the same ID (lbl_emailNewsletter): if I change the ID of the label into the ItemTemplate, both the String oldmail and newmail throws an exception of null Reference ; clearly the problem is that when I click on ImageButton Img_Aggiorna with CommandName="Update", ASP.NET for a mysterious reason Find only controls of ItemTemplate instead of EditItemTemplate from the edited row.
GridView event "OnRowUpdating" is useful only if you use a datasource : in this case is possible to access to the Dictionary e.OldValues[] or e.NewValues[] and get correctly the old and new values.
I have solved the problem using the event "OnRowCommand" with a personalized CommandName and a CommandArgument with the old values : in this case is possible to access to all the controls inside the edited row in the GridView with the new values.
<asp:ImageButton ID="Img_Update" runat="server" CommandName="Change" CommandArgument='<%# Eval("emailNewsletter") %>' ImageUrl="~/images/GridIcon/update.png" ToolTip="Update" />
protected void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "Change":
ImageButton btnNew = e.CommandSource as ImageButton;
GridViewRow row = btnNew.NamingContainer as GridViewRow;
TextBox txt_emailNewsletter = row.FindControl("txt_emailNewsletter") as TextBox;
if ( !CheckEmail(e.CommandArgument.ToString()) || !CheckEmail(txt_emailNewsletter.Text) )
lbl_result.Text = "ERROR : Email not Valid";
else {
if (txt_emailNewsletter.Text.Trim().ToLower() == e.CommandArgument.ToString())
lbl_result.Text = "Email values are indentical";
else
{
//Business Layer Call
NewsLetterBL newsBl2 = new NewsLetterBL();
if (newsBl2.ModifyWrongEmail(e.CommandArgument.ToString(), txt_emailNewsletter.Text.Trim().ToLower()))
lbl_result.Text = "Email Changed";
else
lbl_result.Text = "ERROR : " + newsBl2.LastMessage;
}
}
LoadDataForGridView(((GridView)sender));
BindGridView(((GridView)sender), -1, ((GridView)sender).PageIndex);
break;
}
}
So I have this problem with one of my pages, which basically lists out a bunch of comments for a specified student. The comments are supposed to be editable, but I'm having a problem with getting the contents of a row (so I can display the comment content in a TextBox and allow for edits).
The issue is that whenever I access the GridViewRow from the GridView like such:
this.CommentList.Rows[e.NewEditIndex]
It is returning a collection of cells, but whenever I try access the a cell like so: row.Cells[0].Text (where row is the selected GridViewRow object) it doesn't return any values.
Here is my .aspx code:
<asp:GridView ID="CommentList" runat="server" AutoGenerateColumns="False" CellPadding="5"
ShowHeader="false" Width="100%" DataKeyNames="CommentId" OnRowDeleting="CommentList_RowDeleting"
OnRowCancelingEdit="CommentList_RowCancelingEdit" OnRowEditing="CommentList_RowEditing">
<Columns>
<asp:TemplateField HeaderText="Student ID">
<ItemTemplate>
<b>Author:</b>
<%# ((Comment)Container.DataItem).Author.Name %>
<br />
<b>Date:</b>
<%# ((Comment)Container.DataItem).Created %>
<hr style="border-top: solid 1px black" />
<div style="text-align: center;">
<asp:Panel ID="OptionsPanel" runat="server">
<asp:LinkButton ID="DeleteLinkButton" CommandName="Delete" runat="server" OnClientClick="return confirm('Are you sure you want to delete this comment?');">Delete</asp:LinkButton>
|
<asp:LinkButton ID="EditLinkButton" runat="server" CommandName="Edit">Edit</asp:LinkButton>
</asp:Panel>
<asp:Panel ID="EditOptionsPanel" runat="server" Visible="false">
<asp:LinkButton ID="CancelEditLinkButton" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
</asp:Panel>
</div>
</ItemTemplate>
<ItemStyle CssClass="topLeftJustify" Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Panel ID="ViewCommentPanel" runat="server">
<%# ((Comment)Container.DataItem).Content%>
</asp:Panel>
<asp:Panel ID="EditCommentPanel" runat="server" Visible="false">
<asp:TextBox ID="Comment" runat="server" CssClass="textEntry" TextMode="MultiLine"
Width="100%" Height="100px"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
<ItemStyle CssClass="topLeftJustify" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is my .aspx.cs code (that relates to the code above):
protected void CommentList_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
GridViewRow row = this.CommentList.Rows[e.NewEditIndex];
((Panel)row.FindControl("OptionsPanel")).Visible = false;
((Panel)row.FindControl("EditOptionsPanel")).Visible = true;
((Panel)row.FindControl("ViewCommentPanel")).Visible = false;
((Panel)row.FindControl("EditCommentPanel")).Visible = true;
// problem is with this line. it doesn't show the contents of the "comment"
((TextBox)row.FindControl("Comment")).Text = row.Cells[0].Text;
}
catch (Exception ex)
{
this.Messages.ChangeMessage(ex.Message, MessageType.Error);
}
}
When you use a TemplateField you cannot use e.Row.Cells[index].Text to access a control text of the cell. I would simply add a Label to the panel.
But you can also try it this way:
Panel ViewCommentPanel = (Panel) e.Row.FindControl("ViewCommentPanel");
LiteralControl objPanelText = ViewCommentPanel.Controls[0] as LiteralControl;
TextBox Comment = (TextBox) row.FindControl("Comment");
Comment.Text = objPanelText.Text;