command field of grid view in updatepanel didnt work - c#

I have a grid view with some command field (delete, edit),they work until I put the grid view in an update panel.
it is a asp.net web form.
thank a lot... I'm not use to work with asp.net
<h2><%: Title %>Contact List</h2>
<h3>click any contact to edit...</h3>
<asp:Button ID="insert1" runat="server" Height="21px" OnClick="insert1_Click" Text="new contact" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:contact_atidConnectionString %>"
SelectCommand="SELECT * FROM [contact_list]"
DeleteCommand="delete from [contact_list] where id=#id"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1" Height="30px"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="453px"
OnRowDeleted="GridView1_RowDeleted" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EnablePersistedSelection="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True" />
<asp:BoundField DataField="first name" HeaderText="first name" SortExpression="first name" />
<asp:BoundField DataField="last name" HeaderText="last name" SortExpression="last name" />
<asp:CommandField ShowDeleteButton="True" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>

I found my problem! I simply forget to put the list view that the commad button have to open in the update panel.
here is the correct code:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1" Height="30px"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="453px"
OnRowDeleted="GridView1_RowDeleted" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EnablePersistedSelection="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
CssClass="table table-striped">
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True" />
<asp:BoundField DataField="first name" HeaderText="first name" SortExpression="first name" />
<asp:BoundField DataField="last name" HeaderText="last name" SortExpression="last name" />
<asp:CommandField ShowDeleteButton="True" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:contact_atidConnectionString %>"
SelectCommand="SELECT * FROM [contact_list]"
DeleteCommand="delete from [contact_list] where id=#id"></asp:SqlDataSource>
<asp:Panel runat="server">
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource2" Visible="true">
<ItemTemplate>
<tr runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="SAVE" CommandName="save" OnClick="EditButton_Click" CssClass="btn btn-default btn-lg" BackColor="MediumSpringGreen" />
</td>
<td>
<asp:TextBox ID="TextBox101" runat="Server" Text='<%#Eval("id") %>' Visible="false" class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="FirstNameLabel" runat="Server" Text='<%#Eval("first name") %>' class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="LastNameLabel" runat="Server" Text='<%#Eval("last name") %>' class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="TextBox1" runat="Server" Text='<%#Eval("[street]") %>' class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="TextBox5" runat="Server" Text='<%#Eval("born date") %>' class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="TextBox2" runat="Server" Text='<%#Eval("house number") %>' class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="TextBox3" runat="Server" Text='<%#Eval("telephone") %>' class="form-control input-sm" />
</td>
<td>
<asp:TextBox ID="TextBox4" runat="Server" Text='<%#Eval("pelephone") %>' class="form-control input-sm" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
thank you :)

Related

Saving Calendar Selected Date to SQL database ASP.net

I am developing a little project for a local school and I am pretty much what you can call a newbie in programming.
I am trying to retrieve a selected date by the user in the calendar to save to a separate database. I have an Entity Framework model (.edmx) to link the table in Visual Studio that I need.
This is what I got so far:
ASP.net:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="main_banner">
</div>
<div class="main_container">
<div class="main_heading">
<h1 class="main_title">Projector Inspection</h1>
<p>Add new Projector</p>
</div>
<div class="info_container">
<div>
<asp:Label ID="RoomNolbl" runat="server" Text="Room No:"></asp:Label>
</div>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Roomsdbo" DataTextField="Room_No" DataValueField="Room_No" AutoPostBack="True">
<asp:ListItem>---Select Room---</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="Roomsdbo" runat="server" ConnectionString="<%$ ConnectionStrings:iPadLoanConnectionString2 %>" SelectCommand="SELECT [Room_No] FROM [tblRooms]"></asp:SqlDataSource>
</div>
<div>
<asp:Label ID="Datelbl" runat="server" Text="Date Checked:"></asp:Label>
</div>
<div>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px" NextPrevFormat="FullMonth" Width="350px" OnSelectionChanged="Calendar1_SelectionChanged1" DayNameFormat="Shortest">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="White" BorderColor="#ae1022" BorderWidth="4px" Font-Bold="True" Font-Size="12pt" ForeColor="#ae1022" />
<TodayDayStyle BackColor="#CCCCCC" />
</asp:Calendar>
<asp:TextBox ID="Calendartxt" runat="server" ReadOnly="True"></asp:TextBox>
</div>
<div class ="info_container_task">
<h3>Task carried</h3>
<div>
<asp:Label ID="CheckBoxFilterlbl" runat="server" Text="Filter Cleaning:"></asp:Label>
<asp:CheckBox ID="CheckBoxFilter" runat="server" OnCheckedChanged="CheckBoxFilter_CheckedChanged" AutoPostBack="true" />
</div>
<div>
<asp:Label ID="CheckBoxBulblbl" runat="server" Text="Bulb Replacement:"></asp:Label>
<asp:CheckBox ID="CheckBoxBulb" runat="server" OnCheckedChanged="CheckBoxBulb_CheckedChanged" AutoPostBack="true"/>
</div>
<div>
<asp:Button ID="ButtonSubmit" runat="server" Text="Submit" OnClick="ButtonSubmit_Click" />
</div>
</div>
<div>
<asp:Label ID="HourCountBulblbl" runat="server" Text="Bulb Hours:"></asp:Label>
</div>
<div>
<asp:TextBox ID="HourBulbtxt" runat="server" ></asp:TextBox>
</div>
<div>
<asp:Label ID="FilterHourlbl" runat="server" Text="Filter Hours:"></asp:Label>
</div>
<div>
<asp:TextBox ID="FilterHourtxt" runat="server" ></asp:TextBox>
</div>
<div>
<asp:Label ID="Commentslbl" runat="server" Text="Additional Comments:" ></asp:Label>
</div>
<div>
<textarea id="Commentstxt" cols="20" rows="2" ></textarea> </div>
</div>
</div>
<div class="sub_container">
<h2>Additional Information</h2>
<div class="Tbl_Projectorinfo">
<div class="projectorGrid">
<asp:GridView ID="projectorinfo" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="linkprojectorsdbo" ForeColor="#333333" GridLines="None" DataKeyNames="Model_No">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Current_Hours" HeaderText="Current_Hours" SortExpression="Current_Hours" />
<asp:BoundField DataField="Last_Replacement_Date" HeaderText="Last_Replacement_Date" SortExpression="Last_Replacement_Date" />
<asp:BoundField DataField="Last_Cleaned" HeaderText="Last_Cleaned" SortExpression="Last_Cleaned" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#ae1022" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#ae1022" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
<asp:SqlDataSource ID="linkprojectorsdbo" runat="server" ConnectionString="<%$ ConnectionStrings:iPadLoanConnectionString %>" SelectCommand="SELECT [Model_No], [Current_Hours], [Last_Replacement_Date], [Last_Cleaned] FROM [tblProjectors] WHERE ([Room_No] = #Room_No)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Room_No" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="tblModels" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
<asp:BoundField DataField="Model_Name" HeaderText="Model" SortExpression="Model_Name" />
<asp:BoundField DataField="Min_Hours" HeaderText="MinHours" SortExpression="Min_Hours" />
<asp:BoundField DataField="Max_Hours" HeaderText="MaxHours" SortExpression="Max_Hours" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#ae1022" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#ae1022" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="tblModels" runat="server" ConnectionString="<%$ ConnectionStrings:iPadLoanConnectionString %>" SelectCommand="SELECT [Manufacturer], [Model_Name], [Min_Hours], [Max_Hours] FROM [ProjectorsRoom2017] WHERE ([Room_No] = #Room_No)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Room_No" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
.cs File:
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
tblProjector entry = new tblProjector();
entry.Last_Cleaned = Convert.ToDateTime(Calendartxt.Text);
iPadLoanEntities db = new iPadLoanEntities();
db.tblProjectors.Add(entry);
db.SaveChanges();
}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
Calendartxt.Text = Calendar1.SelectedDate.ToShortDateString();
}
}
I am constantly getting an error saying validation for one or more than one entities failed. Also the error points to the line of code:
db.SaveChanges();
I know that with that code I am trying to get the information of the TextBox that is linked to the calendar to be saved to the database but to be honest saving it directly from the calendar would be great if it is possible.
If anyone could give me a hand on how to be able to achieve this I would be grateful. Thanks

Adding blank row in gridview with button in footer

I have gridview with footer and addbutton on that, how to add new rows if I push the addbutton ? so I can enter new data on that. I also want save them all into database, can somebody explain please
this my front code:
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" ShowFooter="True" Width="707px" >
<AlternatingRowStyle BackColor="White"/>
<Columns>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="AddProduct" runat="server" CssClass="button" Text="Add" onclick="AddProduct_Click" ></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField HeaderStyle-Width="120px" HeaderText="Id Trans" DataField="Id_Trans" ShowHeader="False" Visible="False">
<HeaderStyle Width="120px"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Nama Barang" SortExpression="Nama_Item">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="tampilbarang" DataTextField="Nama_Item" DataValueField="Id_Item">
</asp:DropDownList>
<asp:SqlDataSource ID="tampilbarang" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Item]"></asp:SqlDataSource>
</ItemTemplate>
<HeaderStyle Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="QTY">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Keterangan Penggunaan">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Aksi">
<ItemTemplate>
<asp:Button ID="Del" runat="server" Height="22px" Text="Delete" Width="57px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
There are a lot of things to explain in answer your question, so instead I'd recommend a good tutorial - try this - https://quickstarts.asp.net/quickstartv20/aspnet/doc/ctrlref/data/gridview.aspx
You can add a button in footer template like this example:
<asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Header 1">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Header 2">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Header 3">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>

ASP.NET : Displaying an alert from C# code-behind

I have an asp.net page with a c# code-behind. I am trying to have the code-behind display an 'alert' if the selected-index of a gridview object is changed without selecting 'confirm' or 'cancel'. The code for detecting if confirm or cancel was selected is working, however my message is never displayed. The 'Alert.Show" code was borrowed from: http://archive.devnewz.com/devnewz-3-20061129JavaScriptAlertShowmessagefromASPNETCodebehind.html .
Alert.show works just fine when tested from the page_load(), for example, but not in my selected_index_changed method. Any idea why? Perhaps having to do with how Alert.Show() is implemented?
if (ChangeAttemptedId && !IsSavedId)
{
Alert.Show("Dispatch assignment saved, but you forgot to click Confirm or Cancel!)");
}
ASP.NET CODE:
<asp:Table ID="Table1" runat="server" CssClass="DefaultTable">
<asp:TableRow runat="server">
<asp:TableCell runat="server" Width="50%" VerticalAlign="Top" HorizontalAlign="Left">
<asp:UpdatePanel ID="detailsUP" runat="server" UpdateMode="Always" ChildrenAsTriggers="True">
<ContentTemplate>
<!--
<asp:Label ID="label1" runat="server" Text="Car To Dispatch: " CssClass="DefaultLabel"></asp:Label>
<asp:DropDownList ID="CarsDDL" runat="server" DataSourceID="VehiclesEDS" DataMember="CarNum" DataTextField="CarNum" AppendDataBoundItems="True" Font-Bold="True">
<asp:ListItem Selected="True" Text="-"></asp:ListItem>
</asp:DropDownList>
-->
<asp:DetailsView ID="RideToAssignDV" runat="server" Height="400px"
Width="400px" AutoGenerateRows="False"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical">
<AlternatingRowStyle BackColor="#DCDCDC" />
<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="AssignedCar" HeaderText="Car"
SortExpression="AssignedCar" NullDisplayText="---" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" NullDisplayText="---" />
<asp:BoundField DataField="Phone" HeaderText="Phone"
SortExpression="Phone" NullDisplayText="---" />
<asp:BoundField DataField="NumPatrons" HeaderText="Size"
SortExpression="NumPatrons" NullDisplayText="---" />
<asp:BoundField DataField="PickupAddress" HeaderText="Pickup Address"
SortExpression="PickupAddress" NullDisplayText="---" />
<asp:BoundField DataField="DropoffAddress" HeaderText="Drop-Off Address"
SortExpression="DropoffAddress" NullDisplayText="---" />
<asp:BoundField DataField="CreatedBy" HeaderText="Created By"
SortExpression="CreatedBy" NullDisplayText="---" />
<asp:BoundField DataField="TimeOfCall" HeaderText="Call Time"
SortExpression="TimeOfCall" ReadOnly="True" NullDisplayText="---" />
</Fields>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" BorderStyle="Inset" BorderColor="#C6940D" HorizontalAlign="Center" Height="25px" />
<FooterTemplate>
<asp:Button ID="confirmButton" runat="server" Text="Confirm" ForeColor="Green" HorizontalAlign="Center" OnClick="confirmButton_Click"/>
<asp:Button ID="cancelButton" runat="server" Text="Cancel" ForeColor="Red" HorizontalAlign="Center"
OnClick="cancelButton_Click" OnClientClick="displayTopTen();" />
</FooterTemplate>
<HeaderStyle BackColor="#004812" Font-Bold="True" />
<PagerStyle BackColor="#999999" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
<asp:TableCell runat="server" Width="50%">
<asp:UpdatePanel ID="mapUP" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="map_canvas" style="height: 400px; width:400px;"></div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:Label ID="GV_Label1" runat="server" Text="Car To Dispatch: " CssClass="DefaultLabel"></asp:Label>
<asp:UpdatePanel ID="SelectCarUP" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="VehiclesGridView" runat="server" AllowPaging="True"
AllowSorting="True" DataSourceID="VehiclesEDS" AutoGenerateColumns="False"
onselectedindexchanged="VehiclesGridView_SelectedIndexChanged"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical" ShowHeaderWhenEmpty="True" AutoPostBack="True">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="GVSelectButton" runat="server" CausesValidation="False"
CommandName="Select" Text="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CarNum" HeaderText="Car" ReadOnly="True"
SortExpression="CarNum" />
<asp:BoundField DataField="CurrPassengers" HeaderText="Passengers"
ReadOnly="True" SortExpression="CurrPassengers" />
<asp:BoundField DataField="MaxPassengers" HeaderText="Capacity" ReadOnly="True"
SortExpression="MaxPassengers" />
<asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True"
SortExpression="Status" />
<asp:BoundField DataField="StartAdd" HeaderText="Pick-Up Address"
ReadOnly="True" SortExpression="StartAdd" />
<asp:BoundField DataField="EndAdd" HeaderText="Drop-Off Address"
ReadOnly="True" SortExpression="EndAdd" />
<asp:BoundField DataField="AvgRideTime" HeaderText="Avg. Ride Time"
ReadOnly="True" SortExpression="AvgRideTime" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#004812" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#C6940D" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#C6940D" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#9F770B" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Description
Assuming i understand your question.
You can use the ScriptManager to show a javascript alert message.
Sample
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"err_msg",
"alert('Dispatch assignment saved, but you forgot to click Confirm or Cancel!)');",
true);
}
More Information
MSDN - ClientScriptManager.RegisterStartupScript Method
private void MessageBox(string message,string title="title")
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), title, "alert('" + message + "');", true);
}
It can be useful:
http://www.codeproject.com/Questions/311503/How-to-use-javascript-alert-message-in-code-behind
If you want a single piece of client-side JavaScript to run when the page loads, you can register a startup script in your code-behind:
if(!ClientScript. IsStartupScriptRegistered(typeof(Page), "alert"))
string script = "<script>";
script += "alert('";
script += "Dispatch assignment saved, but you forgot to click Confirm or Cancel!";
script += "');";
script += "</script>";
ClientScript.RegisterStartupScript(typeof(Page), "alert", script);
}
ASP.NET will take care of putting the <script> in your HTML and calling it when the page is loaded.
Your asp:ListBox must have AutoPostBack="True" if the selected_index_changed event should be raised by changing index.
for example
<asp:ListBox ID="ListBox1" runat="server"
AutoPostBack="True" OnSelectedIndexChanged="selected_index_changed">
<asp:ListItem>one</asp:ListItem>
<asp:ListItem>two</asp:ListItem>
<asp:ListItem>three</asp:ListItem>
</asp:ListBox>'
public static void Alert(string message,Page page)
{
ScriptManager.RegisterStartupScript(page, page.GetType(),
"err_msg",
"alert('" + message + "');",
true);
}

Get value from DetailsView to FormView Textbox in insert mode

I'm trying to get the value from detailsview to formview. I want to set the Book ID/ISBN in formview insert textbox to Book ID/ISBN value from detailsview.
Here's a sample of my code:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="bookid" DataSourceID="detailsDataSource"
ForeColor="#333333" GridLines="None" Height="50px" Width="">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<FooterTemplate>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="reservationid" DataSourceID="reserveDataSource"
ForeColor="#333333" GridLines="None">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="Reserved by"
SortExpression="EmployeeID" />
<asp:BoundField DataField="reservedate" HeaderText="Reserved date"
SortExpression="reservedate" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="reservationid"
DataSourceID="reserveDataSource">
<EditItemTemplate>
reservationid:
<asp:Label ID="reservationidLabel1" runat="server"
Text='<%# Eval("reservationid") %>' />
<br />
bookid:
<asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
<br />
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>' />
<br />
reservedate:
<asp:TextBox ID="reservedateTextBox" runat="server"
Text='<%# Bind("reservedate") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Book ID/ISBN:
<asp:TextBox ID="bookidTextBox" runat="server"
Text='<%# Bind("bookid") %>'/>
<br />
Employee ID:
<asp:TextBox ID="EmployeeIDTextBox0" runat="server"
Text='<%# Bind("EmployeeID") %>' />
<br />
Reserve date:
<asp:TextBox ID="reservedateTextBox0" runat="server"
Text='<%# Bind("reservedate") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Reserve" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
So what I'm trying to do is when a user click the Insert/Reserve book linkbutton the Book ID/ISBN is already set to the Book ID/ISBN in formview insert mode as default.
Any help would be much appreciated ;)
Thanks in advance.
Can you try and check the DetailsView1.SelectedValue
<asp:TextBox ID="bookidTextBox" runat="server"
Text='<%# DetailsView1.SelectedValue %>'/>
Edit:
Now if you want to bind that value to your Insert function of your DetailsView, it will not behave like the other control, since you are using the Bind method for the other control and it provides two way binding.
Now you need to pass that value to inserting evet of DetailsView like as we are assigning values using DetailsView1.SelectedValue but not binding the value.
I hope you understand this theory.
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
e.Values["bookid"] = ((TextBox)DetailsView1.FindControl("bookidTextBox")).Text;
}

problem with paging my gridview

I have a gridview inside of a div that is displayed with ajax. I have the following.
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl="~/images/icon_info.gif" />
<div id="moveMe" style="display:none">
<div style="float:right;">
<asp:LinkButton ID="lnkBtnCloseColHelp" runat="server" Text="X" OnClientClick="return false;" />
</div>
<br /><br />
<table>
<tr>
<td>
<asp:GridView ID="GridView2" Width="400px" runat="server" AutoGenerateColumns="False"
AllowPaging ="True"
BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="noyb"
DataSourceID="noyb"
PagerSettings-Mode="NextPreviousFirstLast">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="noyb" HeaderText="App Name" ReadOnly="True"
SortExpression="noyb" />
<asp:BoundField DataField="Description" HeaderText="Short Descr"
ReadOnly="True" SortExpression="Description" />
<asp:BoundField DataField="LongDescription" HeaderText="Long Descr"
SortExpression="LongDescription" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
<PagerTemplate>
<small 12px""="" style="font-size:xx-small; padding-right">Go To Page</small>
<asp:DropDownList ID="ddlPageSelector" runat="server" AutoPostBack="true"
Font-Size="XX-Small" Height="19px" Width="36px">
</asp:DropDownList>
<asp:ImageButton ID="btnFirst" runat="server" CommandArgument="First"
CommandName="Page" SkinID="pagefirst" />
<asp:ImageButton ID="btnPrevious" runat="server" CommandArgument="Prev"
CommandName="Page" SkinID="pageprev" />
<asp:ImageButton ID="btnNext" runat="server" CommandArgument="Next"
CommandName="Page" SkinID="pagenext" />
<asp:ImageButton ID="btnLast" runat="server" CommandArgument="Last"
CommandName="Page" SkinID="pagelast" />
</PagerTemplate>
</asp:GridView>
</td>
</tr>
</table>
</div>
<ajaxToolkit:AnimationExtender ID="ae"
runat="server" TargetControlID="ImageButton2" >
<Animations>
<OnClick>
<Sequence>
<EnableAction Enabled="false"></EnableAction>
<StyleAction AnimationTarget="moveMe" Attribute="display" Value=""/>
<Parallel AnimationTarget="moveMe" Duration="1" Fps="30">
<Move Horizontal="350" Vertical="200"></Move>
<FadeIn Duration=".5"/>
</Parallel>
<Parallel AnimationTarget="moveMe" Duration=".5">
<Color PropertyKey="color" StartValue="#666666" EndValue="#0000FF" />
<Color PropertyKey="borderColor" StartValue="#666666" EndValue="#FF0000" />
</Parallel>
</Sequence>
</OnClick>
</Animations>
</ajaxToolkit:AnimationExtender>
<ajaxToolKit:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="lnkBtnCloseColHelp">
<Animations>
<OnClick>
<Sequence AnimationTarget="moveMe">
<Parallel AnimationTarget="moveMe" Duration=".7" Fps="20">
<Move Horizontal="350" Vertical="-50"></Move>
<Scale ScaleFactor="0.3" FontUnit="px" />
<Color PropertyKey="color" StartValue="#FF0000" EndValue="#666666" />
<FadeOut />
</Parallel>
<StyleAction Attribute="display" Value="none"/>
<StyleAction Attribute="height" Value=""/>
<StyleAction Attribute="width" Value="400px"/>
<EnableAction AnimationTarget="ImageButton2" Enabled="true" />
</Sequence>
</OnClick>
</Animations>
</ajaxToolKit:AnimationExtender>
Why am i not able to page anymore?
Just a thought... maybe you need the GridView in an ajax update panel.

Categories

Resources