I have the following gridview that is inside an updatepanel:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="ButtonAdd" runat="server" OnClick="ButtonAdd_Click" Text="Novo Artigo" />
<asp:GridView ID="Dados" runat="server" AutoGenerateColumns="False" CssClass="Grid">
<Columns>
<asp:TemplateField HeaderText="Artigo">
<ItemTemplate>
<asp:TextBox ID="Artigo" runat="server"></asp:TextBox>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="Artigo"
PopupControlID="PanelArtigos"
>
</asp:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Descrição">
<ItemTemplate>
<asp:TextBox ID="Descricao" runat="server" Width="300px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IVA">
<ItemTemplate>
<asp:TextBox ID="IVA" runat="server" Width="40px" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pr. Unit.">
<ItemTemplate>
<asp:TextBox ID="PU" runat="server" Width="50px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="% Desc.">
<ItemTemplate>
<asp:TextBox ID="Desconto" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UN">
<ItemTemplate>
<asp:TextBox ID="UN" runat="server" Width="50px" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quant.">
<ItemTemplate>
<asp:TextBox ID="Quantidade" runat="server" Width="50px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Liquido">
<ItemTemplate>
<asp:TextBox ID="TotalLiquido" runat="server" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="RemoveArtigo" runat="server" OnClick="RemoveArtigo_Click">Remover
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle Font-Size="Small" />
<RowStyle Font-Size="Small" CssClass="grid" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
As you can see, i have some textbox's.
When i change a value in a textbox, for example, the Desconto value, and leave that textbox, i want that the row where i am to be updated, using the new value present in the textbox. It's like a TextChanged or onBlur, but inside the update panel it's not working.
what is the best way to do it?
I am using VB.NET.
Thank you.
EDIT:
When adding the OnTextChanged="Desconto_TextChanged" i receive this compilation error:
Compilation Error Description: An
error occurred during the compilation
of a resource required to service this
request. Please review the following
specific error details and modify your
source code appropriately.
Compiler Error Message: BC30456:
'Desconto_TextChanged' is not a member
of 'ASP.index_aspx'.
Source Error:
Line 204:
Line 205:
Line 206:
Line 207:
Line 208:
Source File:
C:\inetpub\wwwroot\Facturas\Facturas\index.aspx
Line: 206
TextBox controls will not initiate a postback by default. you can set AutoPostBack to true for each textbox control.
I believe the event you need is TextChanged. Like lincolnk said, you need AutoPostBack set to True for the textbox to fire the postback. Then, inside the event handler, call Dados.DataBind() to reload the GridView's data.
Related
This is my code.I am using a gridview in asp.net.I am trying to add a requiredfieldvalidator to the
textbox_id
in gridview edit mode but nothing happens even if I dont put anything in the textbox and click update.
<Columns>
<asp:BoundField DataField="StudentId" HeaderText="Student_ID" />
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox_id" runat="server" Wrap="False" CausesValidation="true" ValidationGroup="a"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="a" runat="server" ControlToValidate="TextBox_id" ErrorMessage="RequiredField" ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<%--<ItemTemplate>
<asp:Label ID="Label3" runat="server"></asp:Label>
</ItemTemplate>--%>
</asp:TemplateField>
The button that triggers the validation should have
ValidationGroup attribute set to "a" as well.
Try this:
<asp:TemplateField HeaderText="Popolazione residente"
SortExpression="InhabitantsNum">
<EditItemTemplate>
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem,"InhabitantsNum") %>
</itemtemplate>
<asp:TextBox ID="InsertPopolazioneResidente" runat="server"
Text='<%# Bind("InhabitantsNum") %>'></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Inserire un numero positivo" ValidationExpression="^[0-9]+$" ForeColor="Red" ControlToValidate="InsertPopolazioneResidente"></asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="InsertPopolazioneResidente" runat="server"
Text='<%# Bind("InhabitantsNum") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
To summarise, to get validation to work in an Edit Template you need:
A ValidationGroup in the control (Eg TextBox)
The same ValidationGroup in the Validator
The same ValidationGroup in the button etc that triggers the action
CausesValidation="true" in the button etc in step 3
I've dropdown to language based on language selection change master page.
Where as I've gridview , this will bind with data based on language .
When i change language textbox value in gridview is not changing other than that remaining control values are changing .
Here is my Code of gridview
<asp:TemplateField HeaderText="<%$ Resources:AFRResources, Status %>" ItemStyle-CssClass="gridLanguage-status"
SortExpression="STATUS" ItemStyle-HorizontalAlign="Center" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblActive" runat="server" Text='<%# Bind("ACTIVE") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="gridLanguage-status" ForeColor="White" />
<ItemStyle CssClass="gridLanguage-status" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:AFRResources, SeqNo %>" HeaderStyle-CssClass="gridViolation-status"
ItemStyle-CssClass="gridViolation-status" ItemStyle-HorizontalAlign="Center"
HeaderStyle-ForeColor="White" SortExpression="STATUS">
<ItemTemplate>
<asp:Label ID="lblSeqno" runat="server" Text='<%# Bind("SEQUENCENO") %>'></asp:Label>
<asp:TextBox ID="txtSeqNo" runat="server" Width="40%" Text='<%# Bind("SEQUENCENO") %>'
onchange="SetValue()" MaxLength="4" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
but you have to refresh your gridview i mean you could have a method that receives as parameter the selection from your dropdownlist you could maybe use the event SelectedIndexChanged
I am trying to build a simple GridView.
I have a Products table and it contains ProductID and ModelName.
I am using LINQ to SQL
My GridView code is
<asp:GridView ID="GridView1" runat="server" DataSourceID="objData" AutoGenerateColumns="false" AutoGenerateEditButton="true" DataKeyNames="ProductID,ModelName">
<Columns>
<asp:TemplateField HeaderText="Product ID">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("ProductID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Model Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("ModelName") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%#Eval("ModelName") %>'/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and my datasource code is
<asp:ObjectDataSource ID="objData" runat="server" SelectMethod="GetAll" UpdateMethod="UpdateProduct"
DataObjectTypeName="TestLINQProto.tblProduct" TypeName="TestLINQProto.ProductsList"></asp:ObjectDataSource>
I have my update method written like this
[DataObjectMethod(DataObjectMethodType.Update,true)]
public void UpdateProduct(tblProduct product)
{
EshopDataAccess.UpdateProduct(product);//This will call a LINQ function to update the product
}
The issue is that the tblProduct that the UpdateProduct contain original values. It is not getting the updated values.
I think the issue is that you are using Eval method which only supports reading/fetching of data. Use Bind Method in your grid aspx code. Like this
<asp:GridView ID="GridView1" runat="server" DataSourceID="objData" AutoGenerateColumns="false" AutoGenerateEditButton="true" DataKeyNames="ProductID,ModelName">
<Columns>
<asp:TemplateField HeaderText="Product ID">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("ProductID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Model Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("ModelName") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%#Bind("ModelName") %>'/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Data gridview bind the recored with data set.Gird view consist the column "Compnayname"
whenever user click on the column of gridview "Company name" then menu or dropdown control will be display.
so how to add dropdown or menu control in gridview.
I want to data display in grid view control and user click on company name then Menu will be display which contain the information like Send msg, save company detail.
You have to make Template Column
<asp:TemplateField HeaderText="Compnayname">
<ItemTemplate>
<asp:DropDownList ID="ddlCompany" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
here isthe complete GRIDView
<asp:GridView ID="grdList" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="grdList_RowCancelingEdit" OnRowEditing="grdList_RowEditing" OnRowUpdating="grdList_RowUpdating" OnPageIndexChanging="grdList_PageIndexChanging" AllowPaging="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label SkinID="OneColLabel" ID="lblName" runat="server" HeaderText="Edit" />
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnbEdit" runat="server" CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnbUpdate" runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton ID="lnbCancel" runat="server" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drpEditName" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You have to bind Dropdownlist on code behind
I have a GridView that I use to show my users the result of a search. I want to allow them to choose which columns are shown on the GridView when performing their search. Simple enough, yes? I wanted to try doing this using just databinding, no events. Unfortunately, my code fails to update the GridView using checkboxes bound to the column's Visible property. The state of the chechboxes changes, but the Visible property of the columns does not.
Snippet of Search.aspx:
<myControl:FacultyGridView ID="FacultyGridView1" runat="server" />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("HeaderText") %>' Checked='<%# Bind("Visible") %>' AutoPostBack=true/></ItemTemplate>
</asp:Repeater>
Code-behind snippet in Search.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = FacultyGridView1.GridView.Columns;
Repeater1.DataBind();
}
To be clear, the GridView is exposed as a public property of a user control named FacultyGridView. Relevant snippet of FacultyGridView.ascx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" PageSize="25">
<PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
<asp:TemplateField HeaderText="University" SortExpression="UniversityID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("University.Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Division">
<ItemTemplate>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("DivisionMemberships") %>'>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Division.Name") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True" SortExpression="Title" />
<asp:TemplateField HeaderText="Research Type">
<ItemTemplate>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("ResearchTypeMappings") %>'>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ResearchType.Name") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Expertise" HeaderText="Expertise" ReadOnly="True" SortExpression="Expertise" />
<asp:HyperLinkField DataNavigateUrlFields="Website" DataTextField="Website" HeaderText="Website"
SortExpression="Website" />
<asp:BoundField DataField="Phone" HeaderText="Phone" ReadOnly="True" SortExpression="Phone" />
<asp:TemplateField HeaderText="Email Address" SortExpression="EmailAddress">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("EmailAddress", "mailto:{0}") %>'
Text='<%# Eval("EmailAddress") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Finally, I should mention that the GridView is bound by a Button on the page, but I am not getting updates to the Visible property whether I play with the checkboxes before or after databinding. Furthermore, I have not seen my desired behavior when binding the repeater only on the first Page_Load() using if(!IsPostBack), nor by not using Checkbox.AutoPostback true or false. Any clue as to what I'm doing wrong? I expect it to be something simple, but I'm a bit green here.
As a note: I know how to do this easily with events, but I want to do it with databinding as a learning exercise.
Probably because every time the grid is bound to the data, the column & settings are recreated (with-out your changes).