ok i have solved my last question by using update parameters instead und putting templatefields on my gridview instead of boundfields.
it is displayed alright, only thing is the update button doesn't seem to work. when i click it, it just returns to the previous window without updating the data fields in the database.
could you please look at the following code and tell me if i missed something here? thanks....
WORKING:
<asp:GridView DataKeyNames="BenutzerID" ID="grdBenutzer" runat="server" Visible="False" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField ReadOnly="true" DataField="BenutzerID" HeaderText="ID" />
<asp:TemplateField HeaderText="Titel">
<ItemTemplate>
<%# Eval("Titel")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtTitel" Text='<%# Bind("Titel")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bezeichnung">
<ItemTemplate>
<%# Eval("Bezeichnung")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnBezeichnung" Text='<%# Bind("Bezeichnung")%>'>
<asp:ListItem Text="Mitarbeiter" Value="Mitarbeiter"></asp:ListItem>
<asp:ListItem Text="Praktikant" Value="Praktikant"></asp:ListItem>
<asp:ListItem Text="Azubi" Value="Azubi"></asp:ListItem>
<asp:ListItem Text="Umschüler" Value="Umschüler"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vorname">
<ItemTemplate>
<%# Eval("Vorname")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtVorname" Text='<%# Bind("Vorname")%>'/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nachname">
<ItemTemplate>
<%# Eval("Nachname")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtNachname" Text='<%# Bind("Nachname")%>'/>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField ReadOnly="true" HeaderText="Geburtsdatum" DataField="Geburtsdatum" />
<asp:BoundField ReadOnly="true" HeaderText="Geburtsort" DataField="Geburtsort" />
<asp:TemplateField HeaderText="Straße">
<ItemTemplate>
<%# Eval("Straße")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtStraße" Text='<%# Bind("Straße")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nationalität">
<ItemTemplate>
<%# Eval("Nationalität")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtNationalität" Text='<%# Bind("Nationalität")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hausnummer">
<ItemTemplate>
<%# Eval("Hausnummer")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtHausnummer" Text='<%# Bind("Hausnummer")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PLZ">
<ItemTemplate>
<%# Eval("PLZ")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtPLZ" Text='<%# Bind("PLZ")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ort">
<ItemTemplate>
<%# Eval("Ort")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtOrt" Text='<%# Bind("Ort")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Land">
<ItemTemplate>
<%# Eval("Land")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnLand" Text='<%# Bind("Land")%>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobil">
<ItemTemplate>
<%# Eval("Mobil")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtMobil" Text='<%# Bind("Mobil")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField ReadOnly="true" DataField="Status" HeaderText="Status" />
<asp:TemplateField HeaderText="Benutzerart">
<ItemTemplate>
<%# Eval("Benutzerart")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnBenutzerart" Text='<%# Bind("Benutzerart")%>'>
<asp:ListItem Text="Mitarbeiter" Value="Mitarbeiter"></asp:ListItem>
<asp:ListItem Text="Geschäftsführung" Value="Geschäftsführung"></asp:ListItem>
<asp:ListItem Text="Führungskraft" Value="Führungskraft"></asp:ListItem>
<asp:ListItem Text="Administrator" Value="Administrator"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Homepage">
<ItemTemplate>
<%# Eval("Homepage")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtHomepage" Text='<%# Bind("Homepage")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<%# Eval("Email")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtEmail" Text='<%# Bind("Email")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Festnetz">
<ItemTemplate>
<%# Eval("Festnetz")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtFestnetz" Text='<%# Bind("Festnetz")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fax">
<ItemTemplate>
<%# Eval("Fax")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtFax" Text='<%# Bind("Fax")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Urlaubstage">
<ItemTemplate>
<%# Eval("UrlaubstageInsgesamt")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtUrlaubstageInsgesamt" Text='<%# Bind("UrlaubstageInsgesamt")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Ändern" ButtonType="Button" ShowEditButton="true" ShowCancelButton="true" />
<asp:CommandField HeaderText="Neu" ButtonType="Button" ShowInsertButton="true" />
<asp:CommandField HeaderText="Archivieren" ButtonType="Button" ShowDeleteButton="true"/>
</Columns>
</asp:GridView>
Everywhere that you have the following code in your EditItemTemplates:
Text='<%# Eval("fieldName")%>'
You need to change it to this:
Text='<%# Bind("fieldName")%>'
Eval is for one-way (read only) databinding. You want two-way databinding, in order to update the database values.
You also need to set the DataKeyNames property in your GridView:
<asp:GridView ID="grdBenutzer" runat="server" Visible="False" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand" DataKeyNames="BenutzerID" >
This is required for the auto-update functionality to work, per the documentation (linked above):
Use the DataKeyNames property to specify the field or fields that
represent the primary key of the data source. You must set the
DataKeyNames property in order for the automatic update and delete
features of the GridView control to work.
Related
I have looked for a couple of days now and for some reason I am unable to solve my issue. I have a gridview control and wanting to update the row that is selected. I am trying to populate vidInformaiton class, passes to my stored procedure.
<asp:GridView ID="gvVideos" CssClass="gvVideosClass" runat="server"
AutoGenerateColumns="False" DataKeyNames="CustomerId"
OnRowDataBound="OnRowDataBound" OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit"
OnRowUpdating="OnRowUpdating" OnRowDeleting="OnRowDeleting" EmptyDataText="No records has been added.">
<Columns>
<asp:TemplateField HeaderText="Customer">
<EditItemTemplate>
<asp:TextBox ID="customerId" runat="server" Text='<%# Bind("customerId")%>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcustomerID" runat="server" Text='<%# Bind("customerId")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Fid" ItemStyle-Width="50">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
<input type="hidden" name="vidId" value='<%# Eval("fId")%>' />
</ItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("title") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("title") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("typeContent")%>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("typeContent")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Youtube ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ytid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ytid") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("descvid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("descvid") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("thumbnail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("thumbnail") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="SubmitDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("submitdate") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("submitdate") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="160px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkActive" runat="server" Checked='<%# Eval("active")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Categories">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("categories") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("categories") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sort order">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("sortord") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("sortord") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="150"/>
</Columns>
</asp:GridView>
<br />
</div>
My code behind look like this. not sure what I am missing. I can't seem to get the values from the row. I have tried everything, DirectCast, FindControl.
Protected Sub OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim updVid As New VidInformation
Dim updVidRecord As New vidController
Dim row = gvVideos.Rows(e.RowIndex)
updVid.customerId = row.Cells(1).Text.ToString
gvVideos.EditIndex = -1
gvVideos.DataSource = updVidRecord.UpdateVidRecord(updVid)
bindGridview()
End Sub
Converting series of helpful comments to an answer
The correct way to get new values posted to edited GridView row is to use NewValues property of the even args object:
Protected Sub OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
...
Dim updVid As New VidInformation
updVid.customerId = e.NewValues("customerId")
...
End Sub
As to why initial approach did not work. Important thing to realize is that GridView row in question was in edit mode during the previous load of the page. During the post back which edit button triggered new values are posted to the server, but the row is no longer in edit mode, so there are no more edit controls to be found in this row. Thus the method described above is the only by-design way to obtain new values for the row.
I have a grid with 3 columns - Edit, ID, Movie. I would like to add a footer with an Insert link button, 2 textboxes respectively, but unable to do so. Is it possible.
ASPX:
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False"
OnRowEditing="gridview1_RowEditing"
OnRowCancelingEdit="gridview1_RowCancelingEdit"
ShowFooter="true" >
<Columns>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="movie" HeaderText="MOVIE" />
</Columns>
</asp:GridView>
When I try the following, there is an error for commandfield which says, this element is not supported.
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkInsert" runat="server" Text="Insert"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</columns>
The other way would be to use itemTemplate & EditTemplate for each column control. But I find this simple and would like to proceed this way. So Can I add a footer to this structure.
YES, It is possible. But this will require using the <FooterTemplate> inside <TemplateField>. Use TemplateFields for each of the columns and also set the FooterTemplate for each of the columns.
NOTE: The ID column seems here to be a Primary Key. So remove the <FooterTemplate> from the corresponding <TemplateField> defined for ID column, if ID is a Primary Key OR an autogenerated field in your database.
NOTE II: The <FooterTemplate> simply will contain a TextBox only.
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton ID="lnkBtnUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="lnkBtnCancel" runat="server"
CausesValidation="False"
CommandName="Cancel" Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkBtnInsert" runat="server"
CommandName="Insert">Insert</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="lnkBtnDelete" runat="server"
CausesValidation="False"
CommandName="Delete" Text="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:TextBox ID="TextBoxID" runat="server" Text='<%# Bind("ID") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MOVIE">
<EditItemTemplate>
<asp:TextBox ID="TextBoxMovie" runat="server" Text='<%# Bind("Movie") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtMovie" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Movie")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
Now there are 2 ways to insert Data. Either you can use GridView OnRowCommand event or you can handle the OnClick event of your Insert button.
You can't place a commandfield inside TemplateField. But can do like this:
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False"
OnRowEditing="gridview1_RowEditing"
OnRowCancelingEdit="gridview1_RowCancelingEdit"
ShowFooter="true" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<!--To fire the OnRowEditing event.-->
<asp:LinkButton ID="lbEdit" runat="server" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<!--To fire the OnRowDeleting event.-->
<asp:LinkButton ID="lbDelete" runat="server" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkInsert" runat="server" Text="Insert"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="movie" HeaderText="MOVIE" />
</Columns>
</asp:GridView>
Not giving multiline text in gridview cell
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1" ShowFooter="true" AllowPaging="True" AllowSorting="True"
PageSize="5" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="CategoryID" InsertVisible="False" SortExpression="CategoryID">
<ItemTemplate>
<asp:Label ID="lblCategoryID" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryName" SortExpression="CategoryName">
<EditItemTemplate>
<asp:TextBox ID="txtCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="txtDesc" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
None of the textboxes have TextMode set to Multiline.
Set the TextMode property to Multiline on the textbox that you want to be displayed as textarea.
e.g:
<EditItemTemplate>
<asp:TextBox ID="txtCategoryName" Columns="50" Rows="5" runat="server" TextMode="MultiLine" Text='<%# Bind("CategoryName") %>'></asp:TextBox>
</EditItemTemplate>
EDIT
And to make the label wrap, try adding an ItemStyle to it, like this:
<ItemStyle Wrap="true" Width="200" />
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 vs 08 C#,use northwind database . I want wcCategory.ascx file use on gridview cell
Below in my wcCategory.ascx file
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:PopupControlExtender ID="TextBox1_PopupControlExtender" runat="server"
DynamicServicePath="" Enabled="True" ExtenderControlID="" PopupControlID="pnlPopeUp"
TargetControlID="TextBox1">
</cc1:PopupControlExtender>
<asp:Panel ID="pnlPopeUp" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CategoryID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="CategoryID" InsertVisible="False"
SortExpression="CategoryID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("CategoryID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCategoryID" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName"
SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Bellow is my .aspx file
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="SqlDataSource2">
<Columns>
<asp:TemplateField HeaderText="ProductID" InsertVisible="False"
SortExpression="ProductID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProductName" SortExpression="ProductName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SupplierID" SortExpression="SupplierID">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("SupplierID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("SupplierID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("CategoryID") %>'></asp:TextBox>
<br />
<br />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QuantityPerUnit"
SortExpression="QuantityPerUnit">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("QuantityPerUnit") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("QuantityPerUnit") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [CategoryID], [QuantityPerUnit] FROM [Products]">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
I want my .ascx file use on gridview Category cell
Use a placeholder and on rowdatabound use findcontrol to find the placeholder and use loadcontrol to add your usercontrol to the controls collection of the placeholder. Does that help?