when i use template in edit mode with out avalidation control ,when user click edit
lins of grid turn to edit mode and page not send eny postback to server. but when i use
edit template with validation contorol ,the page sending postback to server and page is
reloads all content agaian. how can i fix so page will act like first one
<asp:GridView ID="gridProducts" BorderColor="Black" DataSourceID="sourceProducts" DataKeyNames="ProductID" AutoGenerateColumns="false"
AllowPaging="true" PageSize="3" AllowSorting="true" EnablePersistedSelection="true" runat="server">
<HeaderStyle BackColor="Black" ForeColor="White"/>
<RowStyle BackColor="Gray" ForeColor="White" />
<Columns>
<asp:BoundField HeaderText="ID" ReadOnly="true" SortExpression="ProductID" DataField="ProductID" />
<asp:BoundField HeaderText="NAME" SortExpression="ProductName" DataField="ProductName" />
<asp:BoundField HeaderText="ONE UNIT PRICE" DataFormatString="{0:c}" SortExpression="UnitPrice" DataField="UnitPrice" />
<asp:TemplateField HeaderText="STATUS">
<ItemStyle Width="100px" />
<ItemTemplate>
<b>In Srock:</b>
<%#Eval("UnitsInStock")%><br />
<b>On Order:</b>
<%#Eval("UnitsOnOrder")%><br />
<b>Reorder</b>
<%#Eval("ReorderLevel")%>
</ItemTemplate>
<EditItemTemplate>
<b>In Stock:</b><%#Eval("UnitsInStock")%><br />
<b>On Order:</b><%#Eval("UnitsOnOrder")%><br />
<asp:TextBox ID="txtReorder" runat="server" Text='<%# Bind("ReorderLevel") %>' Width="30px"></asp:TextBox>
<asp:RangeValidator ID="rngValidator" MinimumValue="0"
MaximumValue="100" ErrorMessage="Value Out Of Range" ControlToValidate="txtReorder" EnableClientScript="true" Type="Integer" runat="server">
</asp:RangeValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="true" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sourceProducts" runat="server"
ConnectionString="<%$ConnectionStrings:Northwind%>"
SelectCommand="SELECT ProductID,ProductName,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel
FROM Products WHERE CategoryID=#CategoryID"
UpdateCommand="UPDATE Products SET ProductName=#ProductName,UnitPrice=#UnitPrice,
ReorderLevel=#ReorderLevel WHERE ProductID=#ProductID">
<SelectParameters>
<asp:ControlParameter Name="CategoryID" ControlID="gridCategories" PropertyName="SelectedDataKey.Value" />
</SelectParameters>
</asp:SqlDataSource>
Related
After checking a condition I want to hide or view an image button inside a gridView.
I tried to like this. but it is not working.
<asp:GridView ID="GridView1" runat="server" Width="100%" CssClass="grid" AutoGenerateColumns="False"
EnableModelValidation="True" DataKeyNames="T_ID" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="TEMPL_TITLE" HeaderText="Title">
<HeaderStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="TEMPL_DESC" HeaderText="Description">
<HeaderStyle Width="200px" />
</asp:BoundField>
<asp:BoundField HeaderText="Category" DataField="CAT_NAME" />
<asp:BoundField HeaderText="Workflow Type" DataField="WFTYPE_DESCRIPTION" />
<asp:BoundField HeaderText="Owner" DataField="EMP_CALLING_NAME" />
<%# if(Eval("EXP_PENDING_APPR").ToString() == "0") { %>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ViewImageButton1" runat="server" CommandArgument='<%# Eval("TEMPL_ID") %>'
ImageUrl="Images/jdAttView.gif" OnCommand="btnViewTemplate_Click" ToolTip="View and download template" />
</ItemTemplate>
</asp:TemplateField>
<% } %>
</Columns>
<EmptyDataTemplate>
No templates have been assigned to you security capabilites, Please contact your
local administrator for more information.
</EmptyDataTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
The error with this code
The error with this code
You can apply condition on server control itself.
<asp:ImageButton Visible='<%# Eval("EXP_PENDING_APPR").ToString().Equals("0") %>' ID="ViewImageButton1" runat="server" CommandArgument='<%# Eval("TEMPL_ID") %>' ImageUrl="Images/jdAttView.gif" OnCommand="btnViewTemplate_Click" ToolTip="View and download template" />
I have a GridView table which links to my tblAssets table within SQL Server. I have a "View" hyperlink field which will link to the new page with the AssetID (PK) in the URL. I am wanting to use whichever AssetID is generated in the URL in a SQL View that I have created - I got close whereby clicking on the "View" field will redirect to the page and have the correct URL but will return everything from the SQL View. So I tried to change the SelectCommand but it returned an error.
This is my .aspx code for the GridView:
<form id="frmAssets" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>"
SelectCommand="SELECT * FROM [tblAssets]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="AssetID" DataSourceID="SqlDataSource1" AllowSorting="True" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
Font-Names="Segoe UI" ForeColor="Black" GridLines="Horizontal" style="font-weight: 700" AllowPaging="True" PageSize="20" Font-Size="Small">
<AlternatingRowStyle BorderStyle="None" Font-Overline="False" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="AssetID" DataNavigateUrlFormatString="AssetDetails.aspx?AssetID={0}" Text="View" />
<asp:BoundField DataField="Asset_Tag" HeaderText="Asset Tag" SortExpression="Asset_Tag" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Asset_Type" HeaderText="Asset Type" SortExpression="Asset_Type" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Serial_Number" HeaderText="Serial_Number" SortExpression="Serial_Number" >
<HeaderStyle Width="300px" />
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID" SortExpression="DepartmentID" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
</Columns>
Apologies for the poor embedding.
This is the .aspx code for the page which it redirects to (I'm assuming I need to change the SelectCommand but can't get it working:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Asset Tag" HeaderText="Asset Tag" SortExpression="Asset Tag" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>" SelectCommand="SELECT * FROM [tblAssets]"></asp:SqlDataSource>
Add SelectParameters from http get query to the detail select query
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>" SelectCommand="SELECT * FROM [tblAssets] WHERE AssetID = #AssetID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField ="AssetID" Name="AssetID" Type="Int32" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
Note: when I added an action column with edit delete image into a Telerik grid, the whole grid is disturbed as shown in screenshot.
This only occurs when I want to add action column.
Any help will be highly apprecieted.
Thank you
<telerik:radgrid id="RadGrid1" runat="server" pagesize="20" width="100%"
autogeneratecolumns="False">
<MasterTableView Name="MasterView1" DataKeyNames="Regid" AllowMultiColumnSorting="false">
<ItemStyle CssClass="GridRow1" />
<AlternatingItemStyle CssClass="GridRow2" />
<Columns>
<telerik:GridTemplateColumn HeaderText="Action" DataField="Regid" UniqueName="CkboxDelKey" HeaderStyle-CssClass="LeftGridHeader">
<ItemTemplate>
<nobr>
<asp:ImageButton ID="btnNoteEdit" ToolTip="Edit Goal" ImageUrl="images/EmailAlertEdit.png"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Regid") %>' CommandName="UpdateKeyResult"
runat="server" />
<ItemStyle Width="90px" />
<asp:ImageButton ID="btnDel" ToolTip="Delete Goal" ImageUrl="images/EmailAlertDelete.png"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Regid") %>' CommandName="DelNote" OnClientClick="javascript:return confirm('Are you sure you want to Delete?');"
runat="server" />
<ItemStyle Width="90px" />
</nobr>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" HeaderStyle-CssClass="GridHeader"
SortAscImageUrl="images/EmailAlertsGridAsc.png" SortDescImageUrl="images/EmailAlertGridDesc.png"
SortExpression="LastName" UniqueName="LastName">
<ItemStyle Width="90px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Firstname" HeaderText="Firstname" HeaderStyle-CssClass="GridHeader"
SortAscImageUrl="images/EmailAlertsGridAsc.png" SortDescImageUrl="images/EmailAlertGridDesc.png"
SortExpression="Firstname" UniqueName="Firstname">
<ItemStyle Width="90px" />
</telerik:GridBoundColumn>
<%-- <telerik:GridBoundColumn DataField="KeyResult" HeaderText="Key Result Score" HeaderStyle-CssClass="GridHeader"
SortAscImageUrl="images/EmailAlertsGridAsc.png" SortDescImageUrl="images/EmailAlertGridDesc.png"
SortExpression="KeyResult" UniqueName="KeyResult">
<ItemStyle Width="80px" />
</telerik:GridBoundColumn>--%>
</Columns>
</MasterTableView>
</telerik:radgrid>
What do you expect it to do? At it's heart, the RadGrid is just a table element with rows and columns. If you add one more cell to one of the rows, it will not look right. I suggest making a GridTemplateColumn for every row and deciding whether to show the buttons or not within this cell.
I have a couple of gridviews in my website. Here's the code:
changeSlides.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:ImageField DataImageUrlField="picPath"
DataImageUrlFormatString="PlaceImages/{0}" HeaderText="Picture" ControlStyle-CssClass="editPhotoGridFormat">
<ControlStyle CssClass="editPhotoGridFormat"></ControlStyle>
</asp:ImageField>
<asp:BoundField DataField="PicPath" HeaderText="Filename" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
</Columns>
</asp:GridView>
EditBlogPost.aspx:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateEditButton="True"
DataSourceID="AccessDataSource1"
AutoGenerateColumns="False" DataKeyNames="ID"
AlternatingRowStyle-BackColor="Gray"
AlternatingRowStyle-CssClass="editGridFormat" RowStyle-CssClass="editGridFormat"
RowStyle-VerticalAlign="Top"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="Gray" CssClass="editGridFormat"></AlternatingRowStyle>
<Columns>
<asp:CommandField ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="BlogTitle" HeaderText="BlogTitle"
SortExpression="BlogTitle" />
<asp:ImageField DataImageUrlField="Image" HeaderText="Image"
DataImageUrlFormatString="~/PlaceImages/{0}" ControlStyle-CssClass="editPhotoGridFormat"
AlternateText="Either a wrong file type or a misspelled file name has occurred"
NullDisplayText="No picture on file" >
<ControlStyle CssClass="editPhotoGridFormat"></ControlStyle>
</asp:ImageField>
<asp:BoundField DataField="Caption"
HeaderText="Caption for Picture on Homepage" />
<asp:TemplateField headertext="Text for the homepage">
<EditItemTemplate>
<asp:TextBox id="PicTextBox" runat="server" text='<%# Bind("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("PicText")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TravelDate" HeaderText="Date of Travel"
SortExpression="TravelDate" DataFormatString="{0:MMMMMMMMM, dd, yyyy }" HtmlEncode="false" />
<asp:TemplateField headertext="Top of the Blog Post">
<EditItemTemplate>
<asp:TextBox id="BeginTextBox" runat="server" text='<%# Bind("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("BeginText")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:TemplateField headertext="Text at the End of the Post">
<EditItemTemplate>
<asp:TextBox id="EndTextBox" runat="server" text='<%# Bind("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("EndText")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle VerticalAlign="Top" CssClass="editGridFormat"></RowStyle>
</asp:GridView>
EditPeoplePhotos.aspx:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
DataSourceID="AccessDataSource1" Width="493px">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:ImageField DataImageUrlField="picPath"
DataImageUrlFormatString="photos/PeoplePhotos/{0}" HeaderText="Picture" ControlStyle-CssClass="editPhotoGridFormat">
</asp:ImageField>
</Columns>
</asp:GridView>
My update statements work, but my delete statements don't work in two of the three gridviews. My corresponding delete statements are all virtually the same: "DELETE FROM (Table Name) WHERE ID=?" but I get different error codes, which are as follows:
For changeSlides.aspx, it says "Entry with same key already exists"
For EditBlogPosts.aspx, it work fine. It deletes the blog.
For EditPeoplePhotos.aspx, it says "No value given for one or more required parameters"
Each of those pages use a separate, unrelated table in my database, and each query is only referring to one table, so there are no foreign keys used.
What is going on?
I have grid named 'GridView1' and displaying columns like this
<asp:GridView ID="GridView1" OnRowCommand="ScheduleGridView_RowCommand"
runat="server" AutoGenerateColumns="False" Height="60px"
Style="text-align: center" Width="869px" EnableViewState="False">
<Columns>
<asp:BoundField HeaderText="Topic" DataField="Topic" />
<asp:BoundField DataField="Moderator" HeaderText="Moderator" />
<asp:BoundField DataField="Expert" HeaderText="Expert" />
<asp:BoundField DataField="StartTime" HeaderText="Start" >
<HeaderStyle Width="175px" />
</asp:BoundField>
<asp:BoundField DataField="EndTime" HeaderText="End" >
<HeaderStyle Width="175px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Join" ShowHeader="False">
<ItemTemplate>
<asp:Button ID="JoinBT" runat="server" CommandArgument="<%# Container.DataItemIndex %>" CommandName="Join" Text="Join" Width="52px" />
</ItemTemplate>
<HeaderStyle Height="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Here what is my requirement is whenever we right click on each row in gridview ,it should display three option join meeting(if we click it will go to
meeting.aspx),,view details(will go to detail.aspx),,Subscribe(subscribe.aspx) just like when we click right any where we can see view,sortby,refresh
like that..Do we need to implement javascript here