I was using this file as a reference
http://code.msdn.microsoft.com/VBASPNETGridView-19039173
I would like to follow the sorting function in that demo.
But when I build a simple page . my gridview header is not a hyperlink
I already have sortExpression. but the header stays as regular text (not clickable).
This is the ASPX of my TEST aspx.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplicationSandBox.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="PersonID" HeaderText="PersonID" ReadOnly="False" SortExpression="PersonID" />
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
This is the ASPX file from the demo file. Could you please help me point out which
properties makes the gridview header a hyperlink (clickable)? Thank you
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="DataInMemory.aspx.vb" Inherits="VBASPNETGridView.DataInMemory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvPerson" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
onpageindexchanging="gvPerson_PageIndexChanging"
onrowcancelingedit="gvPerson_RowCancelingEdit"
onrowdatabound="gvPerson_RowDataBound" onrowdeleting="gvPerson_RowDeleting"
onrowediting="gvPerson_RowEditing" onrowupdating="gvPerson_RowUpdating"
onsorting="gvPerson_Sorting">
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="PersonID" HeaderText="PersonID" ReadOnly="False"
SortExpression="PersonID" />
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>
<br />
<asp:LinkButton ID="lbtnAdd" runat="server" onclick="lbtnAdd_Click">AddNew</asp:LinkButton>
<br />
<br />
<asp:Panel ID="pnlAdd" runat="server" Visible="False">
Last name:
<asp:TextBox ID="tbLastName" runat="server"></asp:TextBox>
<br />
<br />
First name:
<asp:TextBox ID="tbFirstName" runat="server"></asp:TextBox>
<br />
<br />
<asp:LinkButton ID="lbtnSubmit" runat="server" onclick="lbtnSubmit_Click">Submit</asp:LinkButton>
<asp:LinkButton ID="lbtnCancel" runat="server" onclick="lbtnCancel_Click">Cancel</asp:LinkButton>
</asp:Panel>
</div>
</form>
</body>
</html>
When i use this code it displays the Header as links - is that what your after?
<asp:GridView ID="GridView1" runat="server" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" AllowSorting="true">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="PersonID" HeaderText="PersonID" ReadOnly="False" SortExpression="PersonID" />
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Gridview is made sortable with the AllowSorting property:
<asp:GridView ID="GridView1"
runat="server"
-->AllowPaging="True" <--
AllowSorting="True" >
<Columns>
{insert your columns}
</Columns>
</asp:GridView>
That will make your headers clickable. The sample page didn't set AllowSorting on the control. The code later in the page shows where they set this in code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' The Page is accessed for the first time.
If Not IsPostBack Then
' Enable the GridView paging option and
' specify the page size.
gvPerson.AllowPaging = True
gvPerson.PageSize = 15
' Enable the GridView sorting option.
--> gvPerson.AllowSorting = True <--
' Initialize the sorting expression.
ViewState("SortExpression") = "PersonID ASC"
' Populate the GridView.
BindGridView()
End If
End Sub
Hope that helps. :)
Related
In my page, I have a gridview with link buttons in a column.
By clicking the link button should show a div below the gridview.
I gave href in onClientClick event of the link button as follows.
function showDiv() {
location.href = '#div1';
}
When I click the link button the div is showing, but after the page load the page goes up.
aspx code
<asp:GridView ID="gridDate" runat="server" CssClass="gridview_Order"
HeaderStyle-BackColor="#09182F" HeaderStyle-ForeColor="#ffffff"
AutoGenerateColumns="false" Visible="False">
<Columns>
<asp:TemplateField ItemStyle-Width="20%" HeaderText="Sl No." ItemStyle-CssClass="paddng">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="DATE" ItemStyle-CssClass="paddng">
<ItemTemplate>
<asp:LinkButton ID="lbtnDate" runat="server" CommandArgument='<%#Eval("tblName") %>' Text='<%# Eval("dtvar") %>' OnClientClick="showDiv()" OnCommand="lbtnDate_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="" ItemStyle-CssClass="paddng">
<ItemTemplate>
<asp:LinkButton ID="lbtnDownload" runat="server" Text="Download Excel" CommandArgument='<%# Eval("tblName") %>' OnCommand="lbtnDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br /><hr /><br />
<div id="div1">
<asp:GridView ID="gridOrderByUser" runat="server" CssClass="gridview"
HeaderStyle-BackColor="#09182F" HeaderStyle-ForeColor="#ffffff"
AutoGenerateColumns="false" Visible="False" >
<Columns>
<asp:TemplateField ItemStyle-Width="2%" HeaderText="Sl No.">
<ItemTemplate>
<asp:Label ID="lblSlNo1" runat="server" Text='<%#Container.DataItemIndex+1 %>' style="color:#000;"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cod" HeaderText="CODE" InsertVisible="False" ReadOnly="True" SortExpression="cod" ItemStyle-Width="16%" />
<asp:TemplateField HeaderText="IMAGE" ItemStyle-Width="18%">
<ItemTemplate>
<asp:Image ID="img1" runat="server" Height="100px" Width="54px" ImageUrl='<%#"~/images/"+Eval("Image") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
So what should I do for staying the page in the div position.
Thanks
If you dont need the server side event of the link button you could do this:
OnClientClick="location.href = '#div1'; return false;"
In my project I am working on showing Task Group and Task (i.e. Parent-child) in one screen with the ability to Add/Edit/Delete the parent (Task Group) record and also to Add/Edit/Delete associated Task. For this I am using nested Grid View (parent-child).
I am implementing the sample application mentioned in the below link to my ASP.NET web based project.
http://www.codeproject.com/Articles/20047/Editable-Nested-GridView-All-in-One
my .ASPX looks as mentioned below:
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Unicorn.Master" CodeBehind="TaskAndTaskGroup.aspx.cs" Inherits="Vipassi.Web.TaskGroup.TaskAndTaskGroup"%>
<asp:Content ID="Content1" ContentPlaceHolderID="phContent" runat="server">
<script language="javascript" type="text/javascript">
function expandcollapse(obj, row) {
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none") {
div.style.display = "block";
if (row == 'alt') {
img.src = "../../Resources/images/minus.gif";
}
else {
img.src = "../../Resources/images/minus.gif";
}
img.alt = "Close to view other TaskGroups";
}
else {
div.style.display = "none";
if (row == 'alt') {
img.src = "../../Resources/images/plus.gif";
}
else {
img.src = "../../Resources/images/plus.gif";
}
img.alt = "Expand to show Tasks";
}
}
</script>
<div>
<asp:GridView ID="GridView1" AllowPaging="True" BackColor="#f1f1f1"
AutoGenerateColumns="false" DataSourceID="ObjectDataSource1" DataKeyNames="task_group_id"
ShowFooter="true" Font-Size="Small"
Font-Names="Verdana" runat="server" GridLines="None" OnRowDataBound="GridView1_RowDataBound"
OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating" BorderStyle=Outset
OnRowDeleting="GridView1_RowDeleting" OnRowDeleted="GridView1_RowDeleted"
OnRowUpdated="GridView1_RowUpdated" AllowSorting="true">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White" />
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("task_group_id") %>', 'one');">
<img id="imgdiv<%# Eval("task_group_id") %>" alt="Click to show/hide Tasks for TaskGroup <%# Eval("task_group_id") %>" width="9px" border="0" src="../../Resources/images/plus.gif" />
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TaskGroup ID" SortExpression="task_group_id">
<ItemTemplate>
<asp:Label ID="lblTaskGroupID" Text='<%# Eval("task_group_id") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblTaskGroupID" Text='<%# Eval("task_group_id") %>' runat="server"></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTaskGroupID" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Group" SortExpression="task_group">
<ItemTemplate><%# Eval("task_group") %></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTaskGroup" Text='<%# Eval("task_group") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTaskGroup" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fiscal Year" SortExpression="Fiscal_Year">
<ItemTemplate><%# Eval("Fiscal_Year") %></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFiscalYear" Text='<%# Eval("Fiscal_Year") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFiscalYear" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Is Active" SortExpression="Active_Flag">
<ItemTemplate><%# Eval("Active_Flag")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtActiveFlag" Text='<%# Eval("Active_Flag") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtActiveFlag" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteTaskGroup" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddTaskGroup" CommandName="AddTaskGroup" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("task_group_id") %>" style="display: none; position: relative; left: 15px; overflow: auto; width: 97%">
<asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" BackColor="White" Width="100%" Font-Size="X-Small"
AutoGenerateColumns="false" Font-Names="Verdana" runat="server" DataKeyNames="task_group_id" ShowFooter="true"
OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating="GridView2_RowUpdating"
OnRowCommand="GridView2_RowCommand" OnRowEditing="GridView2_RowEditing" GridLines="None"
OnRowUpdated="GridView2_RowUpdated" OnRowCancelingEdit="GridView2_CancelingEdit" OnRowDataBound="GridView2_RowDataBound"
OnRowDeleting="GridView2_RowDeleting" OnRowDeleted="GridView2_RowDeleted" OnSorting="GridView2_Sorting"
BorderStyle="Double" BorderColor="#0083C1">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White" />
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Task ID" SortExpression="task_id">
<ItemTemplate>
<asp:Label ID="lblTaskID" Text='<%# Eval("task_id") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblTaskID" Text='<%# Eval("task_id") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task" SortExpression="task_name">
<ItemTemplate><%# Eval("task_name")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTask" Text='<%# Eval("task_name")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTask" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fiscal Year" SortExpression="fiscal_year">
<ItemTemplate><%# Eval("fiscal_year")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTaskFiscalYear" Text='<%# Eval("fiscal_year")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTaskFiscalYear" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Is Active" SortExpression="Active_Flag">
<ItemTemplate><%# Eval("Active_Flag")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTaskActiveFlag" Text='<%# Eval("Active_Flag")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTaskActiveFlag" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteTaskGroup" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddTask" CommandName="AddTask" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource SortParameterName="sortExpression" EnablePaging="true" ID="ObjectDataSource1"
MaximumRowsParameterName="maxRecords" TypeName="Vipassi.BLL.Classes.TaskGroup.TaskGroupBLL"
SelectMethod="ListforTaskGroup" SelectCountMethod="ListCountforTaskGroup" StartRowIndexParameterName="startIndex"
runat="server">
<SelectParameters>
<asp:SessionParameter SessionField="orgId" Name="orgId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
Option 1:
You can disable the VIEWSTATE of ASPX page /User Control :
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="~/TaskAndTaskGroup.aspx.cs" Inherits="Vipassi.Web.TaskGroup.TaskAndTaskGroup" EnableViewState="false"%>
Option 2:
You can also change your source code to make sure the controls added during a post-back must match the type and position of the controls added during the initial request.
Hope this will help you.
I am a beginner in Asp.Net. I have a datalist populated with images. What i want is to know what image was clicked so that I can redirect the user to a different page as per the image clicked inside the datalist.
Here is my source:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MediaCenter.aspx.vb" Inherits="Default2" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Categories<br />
<br />
<br />
<asp:DataList ID="dtlCat" runat="server" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center" OnItemCommand="CatSelect" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server"
Text='<%# Eval("FolderName") %>' />
<br />
<img src="<%# ResolveUrl(String.Format("~/img/apple-touch-icon-114x114.png", Container.DataItem)) %>" onclick="cat_select" />
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
I've given comments inside the code to explain how it works.
Your HTML Designer :
<asp:datalist id="DataList1" runat="server" onitemcommand="dtlCat_ItemCommand" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server" Text='<%# Eval("FolderName") %>' />
<br />
<%--Here the "ImageID" is the Id coming from your Database--%>
<asp:ImageButton ID="ImgBtnViewInq" runat="server" ImageUrl="~/images/Viewmail.png" CommandName="View" CommandArgument='<%# Eval("ImageID") %>' ToolTip="View" />
<%--You can do the same from your link button here too the "ImageID" is the Id coming from your Database--%>
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" CommandArgument='<%# Eval("ImageID") %>' ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:datalist>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
C# Code Behind :
protected void dtlCat_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "View")
{
// Here "i" will get the imageid(CommandArgument='<%# Eval("ImageID") %>') that was given inside the image button tag
int i = Convert.ToInt32(e.CommandArgument);
Response.Redirect("YourPage.aspx?clickedimgID=" + i);
}
if (e.CommandName == "show")
{
// Here "i" will get the imageid (CommandArgument='<%# Eval("ImageID") %>') that was given inside the Link button tag
int i = Convert.ToInt32(e.CommandArgument);
Response.Redirect("YourPage.aspx?clickedimgID=" + i);
}
}
Hope that helps
Try this
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MediaCenter.aspx.vb"
Inherits="Default2" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.11.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Categories<br />
<br />
<br />
<asp:DataList ID="dtlCat" runat="server" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server"
Text='<%# Eval("FolderName") %>' />
<br />
<img src="<%# ResolveUrl(String.Format("~/img/apple-touch-icon-114x114.png", Container.DataItem)) %>"/>
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Hope this may helps you. Let me Know if it helps you.
I am using a data grid in an ASP.NET page to display a data table.
I am not using paging.
If I click "update" the page reloads, changing that specific row to update mode. The problem is that I have to scroll back down to the row to enter the data. I want it to automatically jump down to that row.
The same thing happens when submitting the update. It reloads, but stays at the top of the page. Instead, I want it to jump back down to the row that was just updated.
Update: adding code block. I can get the tag to output in each row of the data grid, but not sure where or how to do the script part...
The Form:
<form id="FORMNAME" runat="server">
The DataGrid:
<asp:GridView ID="dataGrid" DataKeyNames="ID" DataSourceID="RESORTS" AllowSorting="True" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:CommandField ShowEditButton="True" ButtonType="Button" HeaderText="" />
<asp:BoundField DataField="ID" HeaderText="KEY" SortExpression="ID" ReadOnly="True" />
<asp:TemplateField HeaderText="NAME" SortExpression="NAME">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("HREFID") %>'></asp:Label>
NAME:<br />
<asp:textbox id="NAME" text='<%# Bind("NAME") %>' runat="server"/>
<br />
SITE:<br />
<asp:textbox id="Textbox1" text='<%# Bind("URL") %>' runat="server"/>
<br />
LOGO:<br />
<asp:textbox id="LOGO_URL" text='<%# Bind("LOGO_URL") %>' runat="server"/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("HREFID") %>'></asp:Label>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Parent" SortExpression="PARENT_NAME">
<EditItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("PARENT_NAME") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("PARENT_NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Logo Image" SortExpression="IMGLOGOURL" ItemStyle-CssClass="logoCell">
<EditItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("IMGURL") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("IMGURL") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NOTES" SortExpression="NOTES" ItemStyle-CssClass="textAreaCell">
<EditItemTemplate>
<br />
PARENT:<br />
<asp:DropDownList ID="PARENT_NAME" runat="server" DataSourceID="RESORTS" DataTextField="NAME" DataValueField="ID" SelectedValue='<%# Bind("PARENT_ID") %>'></asp:DropDownList>
<br />NOTES:<br />
<asp:textbox id="NOTES" text='<%# Bind("NOTES") %>' Wrap="true" TextMode="MultiLine" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("NOTESTA") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Thanks,
Gary
Try: MaintainScrollPositionOnPostback="true" on the page directive above, it should work!
If MaintainScrollPositionOnPostback="true" doesnt work for you then add a anchor to each row and use javascript to navigate to it.
e.g:
<a name="row1" />
and use javascript like
window.location.hash="#row1"
Work on Asp.Net C# VS08.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var styleToSelect;
function onOk() {
document.getElementById('GridView1').className = styleToSelect;
}
</script>
<script language="javascript" type="text/javascript">
function GetRowValue(val) {
// alert(val);
document.getElementById("Text1").value = val;
// hardcoded value used to minimize the code.
// ControlID can instead be passed as query string to the popup window
//window.opener.document.getElementById("ctl00_ContentPlaceHolder2_GridView1_txtCOM_NAME").value = val;
//window.opener.document.getElementById('%=txtCOM_NAME.ClientId%>').value = val;
//window.opener.document.getElementById("txtParent").value = val;
//Text1.innerHTML=val;
// alert(val);
// window.close();
}
function Hello()
{
document.getElementById("Text1").value="2";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:LinkButton ID="LinkButton1" runat="server">Please click to select an alternate text style.</asp:LinkButton><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="Button2"
PopupControlID="Panel2"
BackgroundCssClass="modalBackground"
DropShadow="true"
OkControlID="OkButton"
CancelControlID="CancelButton"
OnOkScript="onOk()"
/>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px" CssClass="modalPopup">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="ckb">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button3" runat="server" Text="Button" />
<div align="center">
<asp:Button ID="OkButton" runat="server" Text="OK" OnClick="OkButton_Click" OnClientClick=Hello() />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
<input id="Button4" type="button" value="button" /></div>
</asp:Panel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
After Popup .Want to select a row on popup grid then click on ok button and put the value on TextBox fo the parent grid.How to set value on Parent Grid.
I guess you should use the row command event handler of the grid, if I got you right:
OnRowCommand="RowCommand"
Then you can add a button to the grid:
<asp:LinkButton ID="LnkButton" runat="server" CommandName="setValue" CommandArgument='<%# Eval("id")%>'>Set value</asp:LinkButton>
And a method to handle it:
protected void RowCommand(Object sender, GridViewCommandEventArgs e)
if (e.CommandName=="setValue")
[do something with e.CommandArgument and close dialog]