Editing database from front-end, asp.net c# - c#

I'm able to update the database fine, but how do I get the current information extracted from the database into the Edit textboxes.
This is my current code:
<asp:ListView ID="ListView1" runat="server" DataSourceID="Details">
<ItemTemplate>
<div class="col-xs-11">
<asp:Label ID="passwordname" runat="server"
Text="Current Password:" />
<asp:Label ID="password" runat="server"
Text='<%# Eval("Password") %>' />
</ItemTemplate>
</asp:ListView>
<asp:TextBox ID="editpassword" runat="server"
placeholder='<%# Eval("Password") %>' Text="New Password">
</asp:TextBox>
How do I get the textbox editpassword to show the current password stored?

Did you try binding the Value of the asp:TextBox?
Also, instead of using Eval(), consider model binding.
<asp:ListView ID="ListView1" runat="server"
DataSourceID="Details" ItemType="MyNamespace.MyClass">
<asp:TextBox ID="editpassword" runat="server"
Value='<%# BindItem.Password %>' Text="New Password">
</asp:TextBox>
Setting up databind for a listview using c#

Related

Required Field Validator not working properly in gridview

Required Field Validator not working properly in gridview
I work in ASP.NET c# and MySQL database.
I need to make the required field of this DropDownList on FooterTemplate, but Required Field Validator not working.
Why ?
My code:
<FooterTemplate>
<asp:ImageButton ID="imgbtnInsert" runat="server" CommandName="Insert" ImageUrl="/images/icon_2.gif"
ToolTip="Add" OnClientClick="return confirm('Confirm?');" />
</FooterTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtIDDTES" runat="server" CssClass="ddl_Class_new">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rtxtIDDTES" runat="server" ControlToValidate="txtIDDTES"
ErrorMessage="***" Text="*" Display="Dynamic" ValidationGroup="Validation1"
SetFocusOnError="true" EnableClientScript="true"></asp:RequiredFieldValidator>
</FooterTemplate>
<asp:ValidationSummary ID="Validation1" ValidationGroup="Validation1" runat="server" ShowMessageBox="true" />
Can you please help me figure out the problem?
Thanks in advance.
Try this :
<form id="form1" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummaryTop" runat="server" ShowMessageBox="true" ShowSummary="false" />
...
<FooterTemplate>
<asp:DropDownList ID="txtIDDTES" runat="server" CssClass="ddl_Class_new">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rtxtIDDTES" runat="server" ControlToValidate="txtIDDTES"
ErrorMessage="***" Text="*" Display="Dynamic"></asp:RequiredFieldValidator>
</FooterTemplate>

I need to use DataList inside another DataList

<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>
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, please give me full code in code behind part...
for edit DataListOceny .
What you asking is same like the below thread.. You need to find the DataListOceny Control on each row of DataListDziennik to bind it
Using FindControl() to find control
https://msdn.microsoft.com/en-us/library/486wc64h%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
And Here is some good example on the same
http://www.c-sharpcorner.com/UploadFile/rohatash/nested-datalist-in-Asp-Net/
http://surecode.net/DevCentre/NestedDataList/NestedDataList.aspx

get object from listview after clicking a button

I'm trying to get the original object back from a listview, when I click on the button.
I thought it was in e.Item.DataItem but that always seems to be null.
<form runat="server">
<asp:ListView ID="ListList" runat="server">
<ItemTemplate>
<asp:TextBox ID="tbCompanyName" runat="server" Text='<%# Eval("CompanyName") %>'></asp:TextBox>
<asp:TextBox ID="tbEmailAdress" runat="server" Text='<%# Eval("EmailAddres") %>'></asp:TextBox>
<asp:DropDownList ID="ddlAccountManagers" AutoPostBack="True" runat="server" />
<asp:Button runat="server" Text="Create or Update Account" CommandArgument='<%# Container.DataItem.ToString() %>' />
<br />
</ItemTemplate>
</asp:ListView>
</form>
private void ListList_ItemCommand(object sender, ListViewCommandEventArgs e)
{
}
You need to keep the original datasource in session and get the real values while clicking a button.

Mess table in GridView and run time error

I want to create a table as below to interact with database to retrieve, delete, update data.
My output in design view is very messy. And when i try to run the page i receive the following error:
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Please advise me for enhancement based on below data table and my coding.
.aspx:
<div class="modal-bg">
<asp:GridView ID="GridView1" runat="server" EnableEventValidation="false"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" Width="426px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
UsernameLast Login Status
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("UserName") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
Active Role
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ActiveRole") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate >
Full name
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("FullName") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
Email Address
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("EmailAddress") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
Last Login Status
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Last Login Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<button id="newuserbutton" onclick="return newuserbutton_onclick()">
Create New User</button>
Thank you for helps.
Did you actually try to place your control inside the <form runat="server"></form> tags?
Surround your html code with tag => <form runat="server"> ... </form>

Ajax calendar not working

I am using Ajax Calendar for date picker. when i click the calendar image the page will get postback but the calendar popup windows is not getting popup. How to resolve this problem?
Thanks in advance.
<asp:TextBox ID="txt_FromDate" runat="server" AutoPostBack="True"
ontextchanged="txt_FromDate_TextChanged>
</asp:TextBox>
<cc1:CalendarExtender ID="cal_FromDate" PopupButtonID="ibtnFromDate"
runat="server" TargetControlID="txt_FromDate"
Format="MM/dd/yyyy">
</cc1:CalendarExtender>
<asp:ImageButton ID="ibtnFromDate"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"
ImageAlign="Bottom" runat="server"/>
Try This:
<asp:TextBox ID="btn1" runat="server">
</asp:TextBox>
<asp:ImageButton ID="img1" runat="server"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"/>
<cc1:CalendarExtender ID="calendar1" runat="server" PopupButtonID="img1"
TargetControlID="btn1" Enabled="True">
</cc1:CalendarExtender>
<asp:TextBox ID="txtDOB" runat="server" Width="50%"></asp:TextBox>
<cc1:CalendarExtender ID="txtDOB_CalendarExtender" runat="server"
TargetControlID="txtDOB"
Format="MM/dd/yyyy" PopupButtonID="imgDate"
PopupPosition="BottomLeft">
</cc1:CalendarExtender>
<asp:Image ID="imgDate" AlternateText="Image Date"
ImageUrl="~/Images/Calendar.png" runat="server" />
try this,
<asp:TextBox ID="txt_from" placeholder="MM/DD/YYYY" runat="server"
AutoPostBack="True" ontextchanged="txt_from_TextChanged">
</asp:TextBox>
<cc1:CalendarExtender ID="txt_from_CalendarExtender" runat="server"
Format="MM/dd/yyyy" Enabled="True"
TargetControlID="txt_from">
</cc1:CalendarExtender>
no need to use image button for calendar.
You are just missing a Property of CalanderExtender PopupButtonID. try the following
<asp:TextBox ID="txt_FromDate" runat="server" AutoPostBack="True"
ontextchanged="txt_FromDate_TextChanged">
</asp:TextBox>
<asp:ImageButton ID="ibtnFromDate"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"
ImageAlign="Bottom" runat="server"/>
<cc1:CalendarExtender ID="cal_FromDate" PopupButtonID="ibtnFromDate"
runat="server" PopupButtonID="ibtnFromDate"
TargetControlID="txt_FromDate" Format="MM/dd/yyyy">
</cc1:CalendarExtender>

Categories

Resources