me problem is next:
I have a DetailsView control with many editItemTemplates some work fine but i have one dont work's.
code here:
<asp:TemplateField HeaderText="Date" SortExpression="date">
<ItemTemplate>
<%#this.putDate(Eval("fecha")) %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="date" runat="server" ></asp:TextBox>
<asp:CalendarExtender id="CE" runat="server" Format="dd/MM/yyyy"
PopupButtonID="calImg" TargetControlID="date">
</asp:CalendarExtender>
<asp:ImageButton id="calImg" runat="server" CommandName=""
ImageUrl="img/imgCal.gif" />
</EditItemTemplate>
</asp:TemplateField>
In view mode the information appear right but in edit mode after select new date with calendar and pres accept to update information, the data dont update. Any idea?
Thz!
Replace:
<asp:TextBox ID="date" runat="server" ></asp:TextBox>
With:
<asp:TextBox ID="date" runat="server" Text='<%# Bind("SelectedDate") %>'></asp:TextBox>
Related
I want to make one of the data bound in my gridview uneditable or in my case, I want to make the textbox in edit mode in read only. here is what I have tried but not successful:
TextBox ProductImage = GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox;
ProductImage.ReadOnly = true;
and here is the aspx code:
asp:TemplateField HeaderText="ProductImage" SortExpression="ProductImage">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ProductImage") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ProductImage") %>' />
</ItemTemplate>
<ControlStyle Width="50px" />
</asp:TemplateField>
can someone help me out?
Have you tried setting ReadOnly to true in your aspx code?
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true" Text='<%# Eval("ProductImage") %>'/>
</EditItemTemplate>
Or you could use a Label instead of a TextBox
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductImage") %>'/>
In the below code i have a grid view in which i have a textbox i am passing 0 and 1 to check box if it is 1 the checkbox to be checked.I tried but it is not working.Pls help me to solve the issue.
<asp:TemplateColumn HeaderText="Sales Price Ref" ItemStyle-Width="200px" HeaderStyle-VerticalAlign="Top">
<HeaderTemplate>
<asp:Label ID="lblSalesPriceRef" runat="server" Text="Sales Price"></asp:Label>
<br /><br />
<asp:TextBox runat="server" ID="txtSalesPriceRef" AutoPostBack="true" BorderStyle="Solid" BorderColor="#6495ED" BackColor="#B0C4DE" Height="20px" Width="90px" OnTextChanged="txtItem_TextChanged"></asp:TextBox>
</HeaderTemplate>
<EditItemTemplate>
<asp:CheckBox ID="ChSalesPriceRef" runat="server" Checked='<%#Eval("SalesPriceRef")=="1" ? true:false %>' />
<%-- <asp:TextBox ID="txtSalesPriceRef" Width="90px" runat="server" Text='<%#Eval("SalesPriceRef") %>'></asp:TextBox>--%>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSalesPriceRef" runat="server" Text='<%# Convert.ToString(Eval("SalesPriceRef"))== "1" ? "True" :"False" %>' > </asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
YES you can achieve it by binding it to the checkbox
as
<asp:CheckBox ID="ChSalesPriceRef" runat="server" Checked='<%# Bind("SalesPriceRef")%>' Enabled="false" />
if you allow to change checkbox value then make enable=true
I'm using asp and have some textboxes where I want to set the value from code behind. The code below is wrapped inside an asp:DetailsView.
The Textbox I want to get and set value of is InsertItemTemplate with ID=strPositionsName
<asp:TemplateField HeaderText="Name" SortExpression="strPositionName">
<InsertItemTemplate>
<asp:TextBox ID="strPositionName" Width="380px" MaxLength="49" runat="server" Text='<%# Bind("strPositionName") %>'></asp:TextBox>
</InsertItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Textbox1" Width="380px" MaxLength="49" runat="server" Text='<%# Bind("strPositionName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Width="380px" Text='<%# Bind("strPositionName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I managed to get the value by:
var testName = ((TextBox)DetailsView1.FindControl("strPositionName")).Text;
So I tried using this:
((TextBox)DetailsView1.FindControl("strPositionName")).Text = "textboxvalue";
But it didn't work
Try Following Code
TextBox _txtPositionName=(TextBox)DetailsView1.FindControl("strPositionName");
if(_txtPositionName!=null)
_txtPositionName.Text="textboxvalue";
I need to use DataList inside another DataList. It works fine for me, but when I'm trying to do something in code behind with this inside one it just doesn't exist for C#. Here is code:
...
<asp:DataList ID="DataListDziennik" runat="server"
DataSourceID="SqlDataSourcePrzedmioty">
<ItemTemplate>
<asp:Label ID="LabelPrzedmiot" runat="server" Text='<%# Eval("przedmiot") %>' />
...
<asp:DataList ID="DataListOceny" runat="server"
DataSourceID="SqlDataSourceOceny"
RepeatDirection="Horizontal"
OnItemCommand="DataListOceny_ItemCommandOceny"
OnEditCommand="DataListOceny_EditCommandOceny">
<EditItemTemplate>
<asp:TextBox ID="TextBoxOcena" runat="server" Text='<%# Bind("lista") %>' />
<td><asp:Button ID="ButtonZapisz" CommandName="Update" runat="server" Text="Zapisz" /></td>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox Width="20" ID="TextBoxOcena" ReadOnly="true" Text='<%# Eval("lista") %>' runat="server"></asp:TextBox>
<td><asp:Button ID="ButtonEdytuj" CommandName="Edit" runat="server" Text="Edytuj" /></td>
</ItemTemplate>
</asp:DataList>
</td>
</ItemTemplate>
</asp:DataList>
When I write this in code behind:
protected void DataListOceny_EditCommand(object source, DataListCommandEventArgs e)
{
DataListOceny.EditItemIndex = e.Item.ItemIndex;
DataListOceny.DataBind();
}
...Visual Studio tells me that DataListOceny does not exist in current content. I just want to be able edit items on DataListOceny after clicking the "edit" button, it can be placed anywhere on website. Do you know any solution for this problem?
Because DataListOceny is a control inside of another control, you have to make a reference to it by doing something like:
DataList DataListOceny = (DataList)e.Item.FindControl("DataListOceny");
Once you do that, you can use the DataListOceny variable. Hope this helps.
I want to display the TextBox inside a details view in a new line as i am fetching the data from database and trying to make a Form
How do i do this
code
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px"
AutoGenerateRows="False" GridLines="None">
<Fields>
<asp:TemplateField >
<ItemTemplate>
<asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
Please someone help?
try this
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px"
AutoGenerateRows="False" GridLines="None">
<Fields>
<asp:TemplateField >
<ItemTemplate>
<table>
<tr>
<td><asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox></td>
<td><asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
** i have put both data inside single templatefield
You can't
The DetailsView control is based on table-views
If you want to implement your custom design you would have to use the FormView control and use the correct templates. Example:
<asp:FormView runat="server" AllowPaging="true" ID="formView">
<ItemTemplate>
<%--customize the html--%>
</ItemTemplate>
However consider that the DetailsView control automatically creates the design for you, including controls in different modes like Edit, Insert and ReadOnly. When using the FormView control, you will have to provide templates for each mode
Try putting ItemFields in Table Row as follow...
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px" AutoGenerateRows="False" GridLines="None">
<Fields>
<table>
<tr>
<td>
<asp:TemplateField >
<ItemTemplate> <asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox> </ItemTemplate>
</asp:TemplateField>
</td>
<td>
<asp:TemplateField >
<ItemTemplate> <asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label> </ItemTemplate>
</asp:TemplateField>
</td>
</tr>
</table>
</Fields>
</asp:DetailsView>