Enable a LinkButton nested inside a disabled GridView - asp.net

I have a Gridview that has Enabled="False" (it contains many controls and in this circumstance i need them all to be disabled, easiest way is to set Enabled="False" on the Gridview).
The issue is I want to enable one LinkButton on each row within the disabled Gridview. I've tried finding the LinkButton on RowDataBound and enabling it there but it's still disabled. Can this be done? Can you have an enabled Button within a disabled GridView?
Simplified example of the code (real one is thousands of lines long)
<asp:GridView runat="server" enabled="false" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" id="button-to-be-enabled" text="press me"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Related

Template column automatically hides during postback

On the initial load of this page my template column, in an asp data grid, displays fine.
When I click any controls that force a post back the data grid reloads with the template column hidden. There is no visible attribute being set in the html. There is no code changing the visible property of the column in the code-behind.
I tried to hard-code the column's visibility to true and the property reads true in the code-behind but the column still gets hidden.
When trying to hide/show other columns in the data grid I'm unable to change them via the code-behind.
Any ideas on what is causing this column to auto-hide or why I can't effectively change the visible property in the code-behind or html?
<asp:DataGrid ID="dg" runat="server" AllowSorting="True" AutoGenerateColumns="False" CssClass="datagridPWQ">
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" />
<asp:TemplateColumn HeaderText="Add" >
<ItemTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" CommandName="Add"
CssClass="buttonQ" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID")%>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Side note: I have thought about using a ButtonColumn instead but I would still like to know why this doesn't work. I remember seeing a similar error months ago but I don't remember how it was solved.

Add TextBox to DataGrid

I have a web page built in .NET where I am a very simple DataGrid with several fields. I would like to have one of those field have its data placed in a TextBox so the user can edit the default description. Is there an easy way to do this by default so the user doesn't have to click an edit button for the row?
Yes, disable AutoGenerateColumns and define your own fields:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Data") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Updating this data to the database might be more difficult though.

how to add checked event to checkbox in databound datagrid in asp.net?

I have datagridview with multiple columns in my asp.net website. And I am displaying a backend sql stored procedure output into this grid using page OnLoad event. First column in the grid contains a checkbox. I have added this checkbox through ItemTemplate, so that all rows will have a checkbox for selecting the row. I want user able to select the checkbox and based on this selection I would like to perform a DB operation.
currently i am using like below, but couldn't able to trigger the event.
<asp:GridView ID="resultGridView" runat="server" >
<Columns>
<asp:TemplateField HeaderText="Processed">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxProcess" runat="server" OnCheckedChanged="resultgrid_CellContentClick"
Checked="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
on my code behind, I have method resultgrid_CellContentClick() for checkbox selection change event. But this code, never executed when select checkbox on/off.
You didn't set AutoPostBack="true" in your checkbox, that's why your checkbox event handler did not work. Just set it...
<asp:CheckBox ID="CheckBoxProcess" AutoPostBack="true" runat="server"
OnCheckedChanged="resultgrid_CellContentClick" Checked="false" />

Can we avoid postback in gridView...when user click a button in same?

I have a gridview ...in my dotnet 2.0 - web application.
gridview has 2 columns...first column is ID..and second is a "link button"..as shown below.
On click of this link, I have to display a popup..and I'm using ajax ModalPopupExtender.
I am able to see the popup.
But the issue is...when I click on this link button the postback happens...and the gridview.datasource is NULL. So I have to fetch the data from database and bind the gridview again.
Please help me to find a way to avoid this.
<asp:GridView ID="AvailableGridView" >
<Columns>
<asp:BoundField ItemStyle-CssClass="ItemStyleCss" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="GridHeaderRow" HeaderText="ID" DataField="ClaimCodeGroupIdText"
/>
<asp:TemplateField HeaderText="View" ShowHeader="False"> <ItemTemplate>
<asp:LinkButton CssClass="localNavigation" ID="ViewCCGLinkButton"
Text="View" CommandName="View" CommandArgument='<%# Eval("ClaimCodeGroupId") %>' runat="server"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle CssClass="GridHeaderRow" />
</asp:TemplateField>
</Columns>
<asp:GridView />
You can set ajax toolkit modal popup to load client side and not cause a postback.
But if you have to get data from the server side, i think you have following options
Use ajax to load server data
Save the selected Id in the hidden text box and on postback read Id thru hidden textbox
Use jQuery BlockUI and ajax to load server data (personal fav.)
Pick your options according to ur need and requirement.

Gridview buttonfield works LinkButton doesn't

I've been fighting this problem for many hours now and could really use some help :-)
This is the grid
<asp:GridView ID="annonceView" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="dataSourceAnnoncer">
<Columns>
<asp:BoundField DataField="Productname" HeaderText="Productname" />
<asp:buttonfield buttontype="Link" commandname="Delete" text="Delete"/>
<asp:TemplateField HeaderText="Administration">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnDelete" runat="server" Text="Delete" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('Delete?')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="dataSourceAnnoncer" runat="server" ContextTypeName="Namespcae.TheContext"
EnableDelete="True" TableName="Annoncer">
</asp:LinqDataSource>
Clicking the buttonfield deletes the record just fine. Clicking the LinkButton doesn't work. I get a postback and the grid is shown as empty and no record is deleted. Seems like an empty databinding.
I have tried to create a custom OnClick, OnCommand event for the LinkButton, but neither are fired. The OnRowCommand isn't fired either.
I don't manually DataBind in the codebehind.
The problem wasn't with Asp.net but with Sitecore (A CMS), the simple solution is described here, http://www.cassidy.dk/blog/sitecore/2009/01/typesthatshouldnotbeexpanded.html.
I feel like Sitecore has stolen several hours of my life, well the problem is solved, so I'm happy :-)
Your code looks fine and should work. Make sure that you aren't using the lnkBtnDelete Id somewhere else. Do you have both the buttonField and the TemplateField present at the same time? What happens if you remove the buttonfield?

Resources