hide row on clicking delete link in gridview - asp.net

I have a gridview, in which two link buttons are there.
Here it is:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="5" OnRowCommand="gv_RowCommand"
AllowPaging="true" DataKeyNames="ID" CssClass="mGrid" BackColor="White" BorderColor="Silver" BorderStyle="Double"
BorderWidth="1px" CellPadding="4" >
<RowStyle BackColor="White" Width="150%" ForeColor="#003399" />
<Columns>
<asp:TemplateField HeaderText="ID" Visible="false" >
<ItemTemplate>
<asp:Label ID="lblID" Text='<%#Bind("ID") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Version">
<ItemTemplate>
<asp:Label ID="lblversion" Text='<%#Bind("version") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image ID">
<ItemTemplate>
<asp:Label ID="lblimageid" runat="server" Text='<%#Bind("image_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Getty ID">
<ItemTemplate>
<asp:Label ID="lblgettyid" runat="server" Text='<%#Bind("getty_id") %>'></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txtgettyid" Text='<%#Bind("getty_id") %>' runat="server"></asp:TextBox>
</EditItemTemplate>--%>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pool Letter">
<ItemTemplate>
<asp:Label ID="lblpoolletter" runat="server" Text='<%#Bind("pool_letter") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Use">
<ItemTemplate>
<asp:Label ID="lbltouse" runat="server" Text='<%#Bind("to_use") %>'></asp:Label>
</ItemTemplate>
<%-- <EditItemTemplate>
<asp:TextBox ID="txttouse" Text='<%#Bind("to_use") %>' runat="server"></asp:TextBox>
</EditItemTemplate>--%>
</asp:TemplateField>
<asp:TemplateField HeaderText="Clue">
<ItemTemplate>
<asp:Label ID="lblclue" runat="server" Text='<%#Bind("clue") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Range">
<ItemTemplate>
<asp:Label ID="lblrange" runat="server" Text='<%#Bind("range") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="last_updated">
<ItemTemplate>
<asp:Label ID="lbllastupdated" runat="server" Text='<%#Bind("last_updated") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Text='<%#Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First">
<ItemTemplate>
<asp:Label ID="lblfirst" runat="server" Text='<%#Bind("first") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Middle">
<ItemTemplate>
<asp:Label ID="lblmiddle" runat="server" Text='<%#Bind("middle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last">
<ItemTemplate>
<asp:Label ID="lbllast" runat="server" Text='<%#Bind("last") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemStyle Wrap="false" Width="100px" />
<ItemTemplate>
<asp:LinkButton ID="lnkbtnedit" Text="Edit" Visible="true" style="color:#006699;" CommandName="Edit" runat="server"></asp:LinkButton>
<asp:LinkButton ID="lnkbtndel" Text="Delete" Visible="true" style="color:#006699;" CommandName="Delete" runat="server"> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#006699" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#CCFFFF" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
int ID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
con = new SqlConnection(conString);
con.Open();
int v = version + 1 ;
string updatedetails = "update tblfameface set status ='Deleted',version=" + v + " where ID=" + ID + " ";
SqlCommand cmd = new SqlCommand(updatedetails, con);
int temp = cmd.ExecuteNonQuery();
con.Close();
//int rows = GridView1.CurrentCell.RowIndex;
//GridView1.Rows.RemoveAt(rows);
bindDB();
LinkButton btndel = (LinkButton)GridView1.Rows[row.RowIndex].FindControl("lnkbtndel");
btndel.Visible = false;
}
On clicking Edit link,it is working as desired and
When I click on Delete link, I want that row to be hidden.
which event should be fired and how can it be handled?
how can I achieve this??

This is Aspx:
<Columns>
<asp:TemplateField HeaderText="Hide"> <ItemTemplate> <asp:LinkButton ID="lnkHide" runat="server" Text="Hide" OnClick="LnkHide_Click" /> </ItemTemplate> </asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
This is Code behind:
protected void LnkHide_Click(object sender, EventArgs e)
{
GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
clickedRow.Visible = false;
}
Try this code

private void button1_Click(object sender, EventArgs e)
{
int row = dataGridView1.CurrentCell.RowIndex;
dataGridView1.Rows.RemoveAt(row);
}
Try this code........

Related

export gridview to excel is not working with Ajax and Update panel

I have a grid-view in Update panel. there is a link button inside grid-view which fire export command in row command event. There is an another grid-view which get exported on this command code. I debug, the pointers goes in but the export not happening. I know i am missing something here, but not able to get it after spending lot of hours. The Script manager is on master page.
Can any one help please. Below is the code.
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="grd_Report" runat="server" ShowFooter="true" CssClass="ui-jqgrid-btable table-hover" AutoGenerateColumns="false" AllowPaging ="true" PageSize ="12" >
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lbl_CampaignName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CreateDate">
<ItemTemplate>
<asp:Label ID="lbl_CreateDate" runat="server" Text='<%#Eval("CreateDate") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="130px" />
<HeaderStyle Width="130px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="sender">
<ItemTemplate>
<asp:Label ID="lbl_senderID" runat="server" Text='<%#Eval("sender") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="85px" />
<HeaderStyle Width="85px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Text">
<ItemTemplate>
<asp:Label ID="lbl_text" runat="server" Text='<%#Eval("Text") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList class="ui-pg-selbox" ID="drp_itemCount" runat="server" AutoPostBack="true"
onselectedindexchanged="drp_itemCount_SelectedIndexChanged" >
<asp:listItem>10</asp:listItem>
<asp:listItem>15</asp:listItem>
<asp:listItem>50</asp:listItem>
<asp:listItem>100</asp:listItem>
<asp:listItem>200</asp:listItem>
</asp:DropDownList>
</FooterTemplate>
<ItemStyle Width="375px" />
<HeaderStyle Width="375px" />
<FooterStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Count">
<ItemTemplate>
<asp:Label ID="lbl_SMSCount" runat="server" Text='<%#Eval("Count") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" width="80px" />
<HeaderStyle Width="80px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Delivery Count">
<ItemTemplate>
<table class="deliveryCount">
<tr>
<td style="padding:5px;width:180px" colspan="2">Total: <%#Eval("Total")%></td>
</tr>
<table style="font-size:11px;width:180px;">
<tr>
<td style="padding:5px;font-size:11px;width:80px">A: <%#Eval("A")%></td>
<td style="padding:5px;font-size:11px;width:80px">B: <%#Eval("B")%></td>
</tr
<tr>
<td style="padding:5px;font-size:11px;width:80px">2: <%#Eval("2")%></td>
<td style="padding:5px;font-size:11px;width:80px">1: <%#Eval("1")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnk_download" style="font-size:11px;" CommandName="download" CommandArgument='<%#Eval("CampaignId") %>' text="Download" class="ui-icon-document"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" width="100px" />
<HeaderStyle Width="100px" />
</asp:TemplateField>
</Columns>
<HeaderStyle HorizontalAlign="Center" Font-Size="13" Font-Bold="true" />
<RowStyle Font-Names="Helvetica" Font-Size="10" />
<PagerStyle CssClass ="gridviewPager" Height="30px" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="grd_export" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel6" runat="Server">
<ContentTemplate>
<asp:GridView ID="grd_export" runat="server" Visible="false" AutoGenerateColumns ="false" >
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lbl_Name" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:Label ID="lbl_Number" runat="server" Text='<%#Eval("Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="lbl_Id" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Text">
<ItemTemplate>
<asp:Label ID="lbl_text" runat="server" Text='<%#Eval("Text") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="text Id">
<ItemTemplate>
<asp:Label ID="lbl_MessageId" runat="server" Text='<%#Eval("textId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbl_Date" runat="server" Text='<%#Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Credits">
<ItemTemplate>
<asp:Label ID="lbl_Credits" runat="server" Text='<%#Eval("Credits") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Below is the code on Row Command event
If e.CommandName = "download" Then
Dim str As String
str = " select * FROM [Box] where MsgId='" + e.CommandArgument + "'"
Dim com As New SqlCommand(str, con)
Dim da As New SqlDataAdapter(com)
Dim dt As New DataTable
da.Fill(dt)
If Not dt Is Nothing Then
If dt.Rows.Count > 0 Then
grd_export.DataSource = dt
grd_export.DataBind()
grd_export.Visible = True
Response.Clear()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.AddHeader("content-disposition", "attachment;filename=Message.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Me.EnableViewState = False
Dim stringwrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlwrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringwrite)
grd_export.RenderControl(htmlwrite)
Response.Write(stringwrite.ToString())
grd_export.Visible = False
Response.End()
End If
End If
End If
You need to add a postback trigger to your update panel for respose.write to work.

how to fill gridview with checkboxes in asp.net using vb

i have a gridview with pregenerated columns
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="4" GridLines="Horizontal">
<RowStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="MenuID" >
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("MenuID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MenuParentID" >
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("MenuParentID") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Particulars">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Particulars") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="250px" />
</asp:TemplateField>
<asp:BoundField DataField="Options" HeaderText="Options"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Menu(M)" >
<ItemTemplate>
<asp:CheckBox ID="chkMenu" runat="server" OnCheckedChanged="chkMenu_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Add(A)">
<ItemTemplate>
<asp:CheckBox ID="chkAdd" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit(E)">
<ItemTemplate>
<asp:CheckBox ID="chkEdit" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete(D)">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
</asp:GridView>
want to fill the grid from database and check/uncheck the checkboxes from database condition. How to fill the gridview ...................................................................................
On which condition you want to check /Un-check the chechbox?
you can write code on RowDataBound event of grid.
void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// here check the condition and find the check box of current row and set it checked/uncheked
}
}

Gridview rowupdating doesn't work

i have a simple task of updating row, on a click of update linkbutton, as
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" DataKeyNames="ID">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<% #Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<% #Eval("Mobile") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<% #Eval("LName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<% #Eval("LName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="action">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">LinkButton</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server">Update</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
at CS page
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox t1 = GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox;
string s = t1.Text.ToString();
Label3.Text = s;
}
I tried working on this several times but i don't get any answer. what possible code i am missing or there is any error in a code.Thanks for any assistance.
Your LinkButton needs to have a CommandName applied to it in the EditTemplate:
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Update">Update</asp:LinkButton>

Search gridview ItemTemplate textbox value on buttonclick

My Scenario is that i had a gridview,i had taken itemtemplate textboxes and a button,when the gridview is loaded the user enters a ServiceCode based on the ServiceCode and on button click,data should be displayed into the gridview,when the data is displaye in the gridview the user enters the quantity and the discount then the result should be displayed in the netamount,i had written the code but it is not working i would appreciate if someone share thier knowledge with me.
My Axpx Code is:
<asp:GridView ID="GridView1" runat="server" Height="157px" Width="639px"
AutoGenerateColumns="False" BorderWidth="1px"
HorizontalAlign="Justify" onrowdatabound="GridView1_RowDataBound"
BackColor="LightGoldenrodYellow" BorderColor="Tan" CellPadding="2"
ForeColor="Black" GridLines="None" onrowcommand="GridView1_RowCommand">
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="#FFFFC4" Font-Bold="True" ForeColor="#BF6000"/>
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<asp:Label ID="label10" runat="server" Font-Bold="true" ForeColor="#BF6000" Text="<%# Container.DataItemIndex + 1 %>">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Serv Code" >
<ItemTemplate>
<asp:TextBox ID="TxtServiceCode" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceCode") %>'
runat="server" Width="55px">
</asp:TextBox>
<asp:Button ID="Insert" runat="server" BackColor="Ivory" CommandName="InsertRecord"
Font-Bold="True" ForeColor="#BF6000" Text="Insert" onclick="Insert_Click"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="TxtName" runat="server" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Width="150px" Text='<%# DataBinder.Eval(Container, "DataItem.ServiceName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Serv Amt">
<ItemTemplate>
<asp:TextBox ID="TxtServiceAmount" ReadOnly="true" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.ServiceAmount") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:TextBox ID="TxtQuantity" Font-Bold="true" ForeColor="#BF6000" Text='<%# DataBinder.Eval(Container,"DataItem.Quantity") %>'
runat="server" Width="55px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disc Amt">
<ItemTemplate>
<asp:TextBox ID="TxtdiscAmt" Font-Bold="true" ForeColor="#BF6000" Text ='<%# DataBinder.Eval(Container,"DataItem.Discount") %>'
AutoPostBack="true" OnTextChanged="TxtdiscAmt_TextChanged" runat="server" Width="55px"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Amt">
<ItemTemplate>
<asp:TextBox ID="lblNet" runat="Server" Font-Bold="true" ForeColor="#BF6000" Width="55" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
MY CS Code is:
DataSet dss = new DataSet();
SqlConnection MyConnection = new SqlConnection("server=prog;database=mydatabase; UID=sa;PWD=nato123;");
SqlCommand sqlcmd = new SqlCommand("select * from [Bill]", MyConnection);
SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
Instead of using the button OnClick event, I would use OnCommand and pass the item index in the CommandArgument:
<asp:Button ID="Button1" runat="server" OnCommand="Button1_Command" CommandArgument='<%#Container.ItemIndex%>' />
Code-behind:
protected void Button1_Command(object sender, CommandEventArgs e)
{
GridViewRow row = GridView1.Rows[(int)e.CommandArgument];
if (row != null)
{
TextBox txt = row.FindControl("TextBox1") as TextBox;
if (txt != null)
{
string value = txt.Text;
}
}
}

ASP.NET how to hide template field control based on another template field value in GridView

here my code:
<asp:GridView ID="_gvPLCs" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="_dsPLCs" ForeColor="Black" GridLines="Horizontal"
onrowcommand="_gvPLCs_RowCommand" onrowdatabound="_gvPLCs_RowDataBound">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lbnView" runat="server" CausesValidation="false"
CommandName="view" Text="View manual"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PLCName" SortExpression="PLCName">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("PLCName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PLCName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PLCManual" SortExpression="PLCManual">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("PLCManual") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("PLCManual") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LabName" SortExpression="LabName">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("LabName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("LabName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MachineName" SortExpression="MachineName">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("MachineName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("MachineName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MaxAllowedToResDay"
SortExpression="MaxAllowedToResDay">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("MaxAllowedToResDay") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("MaxAllowedToResDay") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
code behind:
protected void _gvPLCs_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow)
return;
if (e.Row.Cells[2].Text == " ")
{
LinkButton lbnview = (LinkButton)e.Row.FindControl("lbnView");
lbnview.Visible = false;
}
}
this doesn't work with me..plz help
what i need is : when there is no a manual;the view manual link disappear
i tested it using this code :
if (e.Row.Cells[2].Text == string.Empty)
{
LinkButton lbnview = (LinkButton)e.Row.FindControl("lbnView");
lbnview.Visible = false;
}
but it always give me "" and always manaul field disappears
try this:
<asp:LinkButton ID="lbnView" runat="server" CausesValidation="false" CommandName="view" Text="View manual" Visible='<%# !string.IsNullOrEmpty(Bind("PLCName").ToString()) %>'></asp:LinkButton>

Resources