I need some help about how to paging data from access data base.
I used asp:ListView and asp:DataPager like some example I found but the paging work with javascript and I want the paging will be friendly.
How I can put some of my code?
[edit]
this is the code:
<asp:ListView ID="tblProjects" runat="server" OnPagePropertiesChanging="tblProjects_PagePropertiesChanging">
<LayoutTemplate>
<ul class="ulProducts">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<div class="divProduct">
<a rel='pics' href='GalleryEditor/pictures/<%# Eval("BigImageName") %>'>
<img src='GalleryEditor/pictures/<%# Eval("SmallImagesName") %>'
alt='<%# Eval("ImageDetail") %>' title='<%# Eval("ImageDetail") %>' />
</a>
</div>
</li>
</ItemTemplate>
<EmptyDataTemplate>
no data
</EmptyDataTemplate>
This the code behind:
protected void tblProjects_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
//set current page startindex, max rows and rebind to false
imagesPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
string page = Request.QueryString["p"];
if (!(FormValidator.IsNumber(page)))
page = "8800";
buildProducts(page);
}
void buildTitleAndDescription(string page)
{
// set page title
OleDbConnection conn0 = new OleDbConnection(#"Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath("GalleryEditor\\App_Data\\projects.mdb"));
OleDbCommand comm0 = new OleDbCommand("select ProjectName from Project where PlaceID=" + page, conn0);
OleDbDataReader reader0;
conn0.Open();
reader0 = comm0.ExecuteReader();
reader0.Read();
Page.Header.Title = reader0["ProjectName"].ToString();
reader0.Close();
conn0.Close();
//if (IsPostBack)
//{
// string Script = "<script type='text/javascript'>goToEnd();\n</script>";
// Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", Script);
//}
}
void buildProducts(string page)
{
// set page content
OleDbConnection conn = new OleDbConnection(#"Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath("GalleryEditor\\App_Data\\sb.mdb"));
OleDbCommand comm = new OleDbCommand("select SmallImagesName, BigImageName, ImageDetail from Images where PlaceID=" + page, conn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(comm);
da.Fill(ds);
tblProjects.DataSource = ds;
tblProjects.DataBind();
}
I do not mind change the code to better one and if I learn form it I will appreciate it.
All the example I found is for SQL and my data need to be on access.
Here is an example of asp listview you will have to define the querystring as follows.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="bd_book_code"
DataSourceID="SqlDataSource1" EnableModelValidation="True">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="bd_book_codeLabel" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:Label ID="bd_isbnLabel" runat="server" Text='<%# Eval("bd_isbn") %>' />
</td>
<td>
<asp:Label ID="bd_titleLabel" runat="server" Text='<%# Eval("bd_title") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:Label ID="bd_book_codeLabel1" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:TextBox ID="bd_isbnTextBox" runat="server" Text='<%# Bind("bd_isbn") %>' />
</td>
<td>
<asp:TextBox ID="bd_titleTextBox" runat="server"
Text='<%# Bind("bd_title") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
<asp:TextBox ID="bd_book_codeTextBox" runat="server"
Text='<%# Bind("bd_book_code") %>' />
</td>
<td>
<asp:TextBox ID="bd_isbnTextBox" runat="server" Text='<%# Bind("bd_isbn") %>' />
</td>
<td>
<asp:TextBox ID="bd_titleTextBox" runat="server"
Text='<%# Bind("bd_title") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="bd_book_codeLabel" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:Label ID="bd_isbnLabel" runat="server" Text='<%# Eval("bd_isbn") %>' />
</td>
<td>
<asp:Label ID="bd_titleLabel" runat="server" Text='<%# Eval("bd_title") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
bd_book_code</th>
<th runat="server">
bd_isbn</th>
<th runat="server">
bd_title</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server" QueryStringField="pid">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="bd_book_codeLabel" runat="server"
Text='<%# Eval("bd_book_code") %>' />
</td>
<td>
<asp:Label ID="bd_isbnLabel" runat="server" Text='<%# Eval("bd_isbn") %>' />
</td>
<td>
<asp:Label ID="bd_titleLabel" runat="server" Text='<%# Eval("bd_title") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
QueryStringField="pid" will do the magic.
Related
I want to validate at least one checkbox select when edit the listview
when the list view have more than one record the validation is not working but its work if the listview have one record.
I think my code not detect the edited record, when its more than one.
what is the problem with this code can some one help with it?
Protected Sub UpdateButton_Click(sender As Object, e As EventArgs)
'get data from chekced checkbox
Dim ChkValue As New List(Of String)()
For Each item As ListViewItem In ListView1.Items
Dim ck1 As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
Dim ck2 As CheckBox = DirectCast(item.FindControl("CheckBox2"), CheckBox)
Dim ck3 As CheckBox = DirectCast(item.FindControl("CheckBox3"), CheckBox)
Dim vl As RequiredFieldValidator = DirectCast(item.FindControl("RequiredFieldValidator1"), RequiredFieldValidator)
If ck1.Checked Or ck2.Checked Or ck3.Checked Then
vl.Enabled = False
sdstt.Update()
Else
vl.Enabled = True
End If
Next
End Sub
<asp:ListView ID="ListView1" runat="server" DataSourceID="sdstt" DataKeyNames="ID" >
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" CausesValidation="true" ValidationGroup="vgrpSaveContact" CommandName="Update" OnClick="UpdateButton_Click" runat="server" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<asp:RequiredFieldValidator Font-Size="6pt" ID="RequiredFieldValidator3" runat="server" ControlToValidate="nameTextBox"
ErrorMessage="first name" SetFocusOnError="true" ValidationGroup="vgrpSaveContact"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revOnlyAlphabetical" runat="server" Font-Size="6pt" ValidationGroup="vgrpSaveContact"
ValidationExpression="^([^0-9]+)$" ControlToValidate="nameTextBox"
ErrorMessage="Invalid Name" Font-Bold="true" ForeColor="Red"></asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="ageTextBox" runat="server" Text='<%# Bind("age") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("chk1") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("chk2") %>' />
</td>
<td>
<asp:CheckBox ID="chkCheckBox3" runat="server" Checked='<%# Bind("chk3") %>' />
<asp:TextBox ID="txtchk" runat="server" Visible="false" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ValidationGroup="vgrpSaveContact" Enabled="false" runat="server"
ControlToValidate="txtchk" ErrorMessage="RequiredFieldValidator">
</asp:RequiredFieldValidator>
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
</td>
<td>
<asp:Label ID="ageLabel" runat="server" Text='<%# Eval("age") %>' />
</td>
<td>
<asp:CheckBox ID="chkCheckBox" runat="server" Checked='<%# Eval("chk") %>' Enabled="false" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">ID</th>
<th runat="server">name</th>
<th runat="server">age</th>
<th runat="server">chk</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
I'm just trying to get accustomed to LVs and I just threw this one together. I was under the impression that the LV would handle the inserting and refreshing of the LV after the insert but it doesn't appear to be the case. I even added the LV.rebind() and still nothing..
I get the LV to refresh/rebind properly after the first insert but subsequent inserts does not produce a refreshed LV. I have confirmed that the records are inserted properly into the database.
Here is my code so far, do I
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ProductID" EnableViewState="true"
datasourceid="sqlDS" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="">
<td>
</td>
<td>
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
</td>
<td>
<asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="CostLabel" runat="server" Text='<%# Eval("Cost") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:Label ID="ProductIDLabel1" runat="server"
Text='<%# Eval("ProductID") %>' />
</td>
<td>
<asp:TextBox ID="CategoryTextBox" runat="server"
Text='<%# Bind("Category") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="CategoryTextBox" runat="server"
Text='<%# Bind("Category") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
</td>
<td>
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
</td>
<td>
<asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="CostLabel" runat="server" Text='<%# Eval("Cost") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
</th>
<th runat="server">
ProductID</th>
<th runat="server">
Category</th>
<th runat="server">
Description</th>
<th runat="server">
Cost</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="sqlDS" runat="server"
DataSourceMode="DataSet" EnableCaching="true"
ConnectionString="<%$ ConnectionStrings:ProjectDashboardConnectionString %>"
SelectCommand="usp_CafeteriaGetProducts" SelectCommandType="StoredProcedure"
FilterExpression="Category='A'"
InsertCommand="usp_CafeteriaInsertProducts" InsertCommandType="StoredProcedure">
<InsertParameters>
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Category" Type="String" />
<asp:Parameter Name="Cost" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
code beind:
Public Class WebForm3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub ListView1_ItemInserted(ByVal sender As Object, ByVal e As ListViewInsertedEventArgs) Handles ListView1.ItemInserted
sqlDS.Dispose()
sqlDS.DataBind()
ListView1.Dispose()
ListView1.DataSourceID = "sqlDS"
ListView1.DataBind()
End Sub
Protected Sub sqlProducts_ItemInserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs) Handles sqlDS.Inserting
''Do something
End Sub
Protected Sub sqlProducts_ItemInserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs) Handles sqlDS.Inserted
''Do something
End Sub
End Class
any ideas?
Thanks.
It was because of the sqldatasource property EnableCaching being set to "true". Removed that property completely as the default is False.
I have 10 questions in my sql database. I get them and print them in Link form using LinkButton. Now i want to generate click event of every question separately.
How to generate OnClick event of LinkButton inside ListView. Please help in easy steps.
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="userid" >
<AlternatingItemTemplate>
<tr style="">
<td>
<%-- <asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
--%>
<h3> <asp:LinkButton CommandArgument='<%# Eval("userid") %>' ID="LinkButton1" runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:TextBox ID="useridTextBox" runat="server" Text='<%# Bind("userid") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<h3> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("userid") %>' runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">qt</th>
<th runat="server">userid</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" SelectCommand="SELECT [qt], [userid] FROM [java]"></asp:SqlDataSource>
ASPX:
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="userid" onitemcommand="ListView1_ItemCommand" >
<AlternatingItemTemplate>
<tr style="">
<td>
<%-- <asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
--%>
<h3> <asp:LinkButton CommandArgument='<%# Eval("userid") %>' ID="LinkButton1" runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="qtTextBox" runat="server" Text='<%# Bind("qt") %>' />
</td>
<td>
<asp:TextBox ID="useridTextBox" runat="server" Text='<%# Bind("userid") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<h3> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("userid") %>' runat="server"><%# Eval("qt") %></asp:LinkButton> </h3>
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">qt</th>
<th id="Th2" runat="server">userid</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="qtLabel" runat="server" Text='<%# Eval("qt") %>' />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
SelectCommand="SELECT [qt], [userid] FROM [java]"></asp:SqlDataSource>
Code Behind:
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
string userid = e.CommandArgument.ToString();
Response.Write("U:" + userid);
if (userid == "USER_3730")
{
Response.Redirect("bnbnbnbnbn.aspx");
}
if (userid == "USER_b163")
{
Response.Redirect("home.aspx");
}
}
I am attempting to get the row and column location of a text boxes OntextChanged.
I can get the column location if I do this:
TextBox txtScore = sender;
ListViewItem item = (ListViewItem)txtScore.NamingContainer;
int col = ((ListView)item.NamingContainer).DataKeys(item.DataItemIndex).Values(0);
which works until I convert the snippet below to a user control.
Code Snippet
<asp:ListView ID="techs" runat="server" ItemPlaceholderID="lvItemPlaceholder" DataKeyNames="Number"
OnItemDataBound="techs_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
Tech
<%# Eval("Number")%>
</td>
<td>
<asp:TextBox ID="tech" runat="server" Text='<%# Eval("Name") %>' />
</td>
<asp:ListView ID="scorePatterns" runat="server" ItemPlaceholderID="lvScorePatternsItemPlaceholder"
OnItemDataBound="scorePatterns_ItemDataBound" DataKeyNames="Ref">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvScorePatternsItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<td>
<table>
<asp:ListView ID="scores" runat="server" ItemPlaceholderID="lvScoresItemPlaceholder"
OnItemDataBound="scores_ItemDataBound" DataKeyNames="Ref,Instance">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvScoresItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox runat="server" ID="txtScore" Width="50" AutoPostBack="true" OnTextChanged="txtScore_TextChanged" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
</td>
</ItemTemplate>
</asp:ListView>
<td>
<asp:Label runat="server" ID="lblDate" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
I have listview and i need to bind the dropdown list in the list view to ListItemCollection which will be built using a function BindPages().
When I clicked on the AddNew Link I am not able to bind the dropdown.
<asp:ListView DataKeyNames="Menuid" OnItemCommand="lvParentMenus_ItemCommand" OnSorting="lvParentMenus_Sorting"
OnDataBound="lvParentMenus_DataBound" DataSourceID="SqlDataSource1" ID="lvParentMenus"
runat="server">
<LayoutTemplate>
<table border="0" id="listview" width="100%" class="grid" cellpadding="0" cellspacing="0">
<thead>
<tr class="listingheader ">
<td width="10%" style="text-align: center; !important">
<input type="checkbox" name="checkbox" id="headercheck" />
</td>
<td id="thsno" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Sno"
Text="Sno" />
</td>
<td id="thmenutext" runat="server">
<asp:LinkButton runat="server" ID="LinkButton2" Text="Menu Text" CommandName="Sort"
CommandArgument="MenuText" />
</td>
<td id="thmenuurl" runat="server">
<asp:LinkButton runat="server" ID="LinkButton3" Text="Menu Url" CommandName="Sort"
CommandArgument="MenuUrl" />
</td>
<td id="thlevel" runat="server">
<asp:LinkButton runat="server" ID="LinkButton4" Text="Level of Display" CommandName="Sort"
CommandArgument="level" />
</td>
<td>
Action
</td>
</tr>
</thead>
<tbody>
<tr runat="server" id="itemPlaceholder">
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" align="center">
<asp:Label ID="lblMessage" Text="dfdfdfd" runat="server"></asp:Label>
</td>
<td align="right">
<asp:LinkButton Text="Add New" ID="lnkNew" CommandName="FillDropDown" runat="server"
Font-Bold="true" OnClick="AddNew"></asp:LinkButton>
</td>
</tr>
</tfoot>
</table>
<ItemTemplate>
<tr class='<%# Container.DataItemIndex % 2 == 0 ? "lrow1" : "lrow1 altrow" %>'>
<td class="col1" align="center">
<asp:CheckBox runat="server" ID="chkitem"></asp:CheckBox>
</td>
<td class="lrow1">
<%# Eval("Sno")%>
<asp:HiddenField ID="hdnStoreID" runat="server" Value='<%# Eval("MenuId") %>' />
</td>
<td>
<%# Eval("MenuText")%>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSource='<%#BindLevel(6)%>' SelectedValue='<%# Eval("level")%>'>
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
|
<asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('Are you sure to delete the current item');">Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="lrow1">
<td class="col1" align="center">
</td>
<td class="lrow1">
</td>
<td class="lrow1">
<asp:TextBox ID="txtMenuText" runat="server" Width="80px" Text='<%# Eval("MenuText")%>'
CssClass="inputbox" ValidationGroup="InsertFields" />
<asp:RequiredFieldValidator ID="reqValidCity" ControlToValidate="txtMenuText" runat="server"
ErrorMessage="City Name is required." Display="Dynamic" ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regValidCity" runat="server" ErrorMessage="Please Enter Alphabets only."
Display="Dynamic" ValidationGroup="g1" ControlToValidate="txtMenuText" ValidationExpression="^[a-zA-Z0-9\s]{2,1000}"></asp:RegularExpressionValidator>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSourceID="sdsLevel" DataValueField="level"
DataTextField="level">
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkinsert" runat="server" OnClick="lnkinsert_Click" ValidationGroup="InsertFields"> Insert</asp:LinkButton>
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="usp_getParentMenus"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddlRoles" Name="intRoleid" PropertyName="Text" DefaultValue="1"
ConvertEmptyStringToNull="true" Direction="Input" />
</SelectParameters>
</asp:SqlDataSource>
and here is the method BindPAges()
protected ListItemCollection BindPages()
{
string sDir = Request.PhysicalApplicationPath;
if (FirstCount == 0)
DirSearch(sDir);
return collection;
}
When I tried to find the ddlPageList in the AddNew() method it is throwing error "Object referenc not set "
AddNEw() Method:
` protected void AddNew(object sender, EventArgs e)
{
lvParentMenus.InsertItemPosition = InsertItemPosition.FirstItem;
lvParentMenus.FindControl("lnkNew").Visible = false;
lvParentMenus.EditIndex = -1;
sdsLevel.ConnectionString = DBConnectionString.ConnectionString;
Parameter a = new Parameter("intRoleid", DbType.Int32);
a.DefaultValue = ddlRoles.SelectedValue.ToString();
sdsLevel.SelectParameters.Add(a);
sdsLevel.SelectCommand = "usp_getParentMenus";
DropDownList ddlpages = (DropDownList)lvParentMenus.FindControl("ddlPagesList");
string sDir = Request.PhysicalApplicationPath;
DirSearch(sDir);
ddlpages.DataSource = collection;
ddlpages.DataBind();
}
Need urgently.
Thanks.
Please try
DropDownList ddlpages = (DropDownList)lvParentMenus.Items[0].FindControl("ddlPagesList");
Have you tried to use runat=server property in TABLE in Listview?