Please help. I am trying to make the rejectcheckbox become invisible based on the CaseStatus item. If CaseStaus = "success" then rejectcheckbox's visible = true. If CaseStatus = "reject" then rejectcheckbox's visible = false.
<ItemTemplate>
<tr
style="">
<td>
<asp:Label ID="emailaddressLabel" runat="server" Text='<%# Eval("emailaddress") %>' />
</td>
<td>
<asp:Label ID="CaseNumberLabel" runat="server" Text='<%# Eval("CaseNumber") %>' />
</td>
<td>
<asp:Label ID="FileUploadToRepositoryTimeLabel" runat="server" Text='<%# Eval("FileUploadToRepositoryTime") %>' />
</td>
<td>
<asp:Label ID="CaseTitleLabel" runat="server" Text='<%# Eval("CaseTitle") %>' />
</td>
<td>
<asp:Label ID="CaseTypeLabel" runat="server" Text='<%# Eval("CaseType") %>' />
</td>
<td>
<asp:HyperLink ID="FileNameLabel" runat="server" Text='<%# Eval("FileName") %>' target ="_blank" NavigateUrl='<%# "~/FileArchives/FileUploadArchive/" + Eval("FileName")%>' Visible='<%# !string.IsNullOrWhiteSpace(Eval("FileName").ToString()) %>'></asp:HyperLink>
</td>
<td style="padding-right: 5px; padding-left: 5px">
<asp:Label ID="CaseStatusLabel" runat="server" Text='<%# Eval("CaseStatus") %>' Font-Bold="True" style='<%# GetUserStatusStyle() %>'/>
</td>
<td>
<asp:LinkButton ID="SessionLinkButton" runat="server" Text='Update' CommandArgument='<%# Eval("SessionId") %>' />
<%--<asp:Label ID="SessionIdLabel" runat="server" Text='<%# Eval("SessionId") %>' />--%>
</td>
<td style="text-align: center">
<asp:CheckBox ID="rejectCheckBox" runat="server" Checked='<%# Eval("reject") %>' OnCheckedChanged="updateRejectStatus_CheckedChanged" Enabled="True" AutoPostBack="True"/>
<%-- <asp:CheckBox ID="rejectCheckBox" runat="server" Checked='<%# Eval("reject") %>' Enabled="True" AutoPostBack="False" />--%>
</td>
</tr>
</ItemTemplate>
Use the on-item data bound event.
So, say I have this markup:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" >
<ItemTemplate>
<tr style="">
<td><asp:Label ID="First" runat="server" Text='<%# Eval("FirstName") %>' /></td>
<td><asp:Label ID="Last" runat="server" Text='<%# Eval("LastName") %>' /></td>
<td><asp:Label ID="Hotel" runat="server" Text='<%# Eval("HotelName") %>' /></td>
<td><asp:Label ID="City" runat="server" Text='<%# Eval("City") %>' /></td>
<td align="center">
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" class="table table-hover">
<tr runat="server" style="">
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">Select</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
Code to load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid
End If
End Sub
Sub LoadGrid()
Using cmdSQL As New SqlCommand("SELECT * FROM tblHotels ORDER BY HotelName",
New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
ListView1.DataSource = cmdSQL.ExecuteReader
ListView1.DataBind()
End Using
End Sub
Output:
Now, lets say for city = "Banff", we want to hide the check box.
So, in data bound event, we could use this:
Protected Sub ListView1_ItemDataBound(sender As Object, e As ListViewItemEventArgs) Handles ListView1.ItemDataBound
If e.Item.GetType = GetType(ListViewDataItem) Then
Dim txtCity As Label = e.Item.FindControl("City")
Dim ckbox As CheckBox = e.Item.FindControl("CheckBox1")
If txtCity.Text = "Banff" Then
ckbox.Visible = False
End If
End If
End Sub
So, now we see this:
so, as a general rule to change color, hide controls etc?
Use the ItemDataBound event.
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 a datalist and a binddata Sub in vb side that works on page load and I can see all my data but then when I click edit it brings up this error:-
Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Here is My vb code:-
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Protected Sub BindData()
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
cmd.Connection = cn
cmd.CommandText = "SELECT DISTINCT Users.User_ID, Users.FirstName, Users.LastName, Users.Password, Users.Email, Users.ContactNum, Users.Address, Users.County, Users.Gender, Users.Datejoined, Users.Dateleft, Users.Subscription_ID, Subscriptions.Subscription_type FROM Users INNER JOIN Subscriptions ON Users.Subscription_ID = Subscriptions.Subscription_ID WHERE (Users.Dateleft IS NULL)"
cn.Open()
Dim ds As SqlDataReader
ds = cmd.ExecuteReader()
MyDataList.DataSource = ds
MyDataList.DataBind()
cn.Close()
End Sub
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
BindData()
MyDataList.EditItemIndex = e.Item.ItemIndex
End Sub
And this is my asp.net :-
<asp:DataList ID="MyDataList"
runat="server"
RepeatColumns="2" CellSpacing="-1" Font-Bold="False" Font-Italic="False"
Font-Names="Arial" Font-Overline="False" Font-Size="Medium"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
ShowFooter="False" ShowHeader="False"
onItemDataBound="myDataList_ItemDataBound"
onEditCommand="myDataList_EditCommand"
onCancelCommand="myDataList_CancelCommand"
onUpdateCommand="myDataList_UpdateCommand"
onDeleteCommand="myDataList_DeleteCommand"
RepeatDirection="Horizontal">
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
VerticalAlign="Middle" />
<ItemTemplate>
<br />
<div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
<table class="style1">
<tr>
<td class="style2">
User ID</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("User_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
Details</td>
<td>
<i><b>
<asp:Label ID="lblFName" runat="server" Text='<%# Eval("FirstName") %>' />
<asp:Label ID="lblLName" runat="server" Text='<%# Eval("LastName") %>' />
</i></b>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="Address" runat="server" Text='<%# Eval("Address") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblCounty" runat="server" Text='<%# Eval("County") %>' />
</td>
</tr>
<tr>
<td class="style2">
Contact Details</td>
<td>
<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblNum" runat="server" Text='<%# Eval("ContactNum") %>' />
</td>
</tr>
<tr>
<td class="style2">
Package ID</td>
<td>
<asp:Label ID="lblSub" runat="server" Text='<%# Eval("Subscription_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblDes" runat="server" Text='<%# Eval("Subscription_type") %>' />
</td>
</tr>
<tr>
<td class="align-center" colspan="2">
<asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnDelete" runat="server" CommandName="Delete" Text="Delete" />
</td>
</tr>
</table></div>
<br />
</ItemTemplate>
<EditItemTemplate>
<table class="style1">
<tr>
<td class="style2">
User ID</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("User_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
Details</td>
<td>
<asp:TextBox ID="txtFName" runat="server" text='<%#Container.DataItem("FirstName")%>'></asp:TextBox>
<asp:TextBox ID="txtLName" runat="server" text='<%#Container.DataItem("LastName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style4">
<asp:TextBox ID="lblAdd" runat="server"
text='<%#Container.DataItem("Address")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:TextBox ID="lblCounty" runat="server"
text='<%#Container.DataItem("County")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Contact Details</td>
<td>
<asp:TextBox ID="lblEmail" runat="server"
text='<%#Container.DataItem("Email")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:TextBox ID="lblNum" runat="server"
text='<%#Container.DataItem("ContactNum")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Package ID</td>
<td>
<asp:Label ID="lblSub" runat="server" Text='<%# Eval("Subscription_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblDes" runat="server" Text='<%# Eval("Subscription_type") %>' />
</td>
</tr>
<tr>
<td class="align-center" colspan="2">
<asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update">Update</asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate><SelectedItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
VerticalAlign="Middle" />
I have put Page EnableEventValidation="false" but that just does nothing, i dont tell the error but nothing happens.
Please help me.
Try changing the following code:
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
BindData()
MyDataList.EditItemIndex = e.Item.ItemIndex
End Sub
to this
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
MyDataList.EditItemIndex = e.Item.ItemIndex
MyDataList.DataBind()
End Sub
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.
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>