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?
Related
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");
}
}
On chkSubModuleView_CheckedChanged() event iwant to get the id of chkModule.Please tell me how to get the id or reference of parent checkbox on click of child checkbox in server side.How to distinguish between different modules .
enter code here
<asp:ListView ID="lvModule" runat="server">
<LayoutTemplate>
<table width="600px" border="0" cellpadding="0" cellspacing="0"
class="ListViewtable">
<tr>
<th style="width: 10%;">
Modules
</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server">
</asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkModule" runat="server"
CausesValidation="false" AutoPostBack="true"
OnCheckedChanged="chkModule_CheckedChanged" >
</asp:CheckBox><asp:HiddenField ID="hfEntityName"
Value='<%# Eval("EntityName") %>' runat="server" />
<%# Eval("Title")%>
<asp:HiddenField ID="hfID" Value='<%# Eval("ID") %>'
runat="server" />
<asp:Label ID="label" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" style="padding-left: 20px;">
<asp:ListView ID="lvSubModule" runat="server">
<LayoutTemplate>
<table width="100%" cellspacing="0" border="0"
class="ListViewtableLayer2">
<tr>
<th style="width: 20%;">
Sub Module
</th>
<th style="width: 20%;">
<asp:CheckBox ID="chkSubModuleView"
Checked="true" runat="server" AutoPostBack="true"
OnCheckedChanged="chkSubModuleView_CheckedChanged" />
View
</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder"
runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("Title")%>
<asp:HiddenField ID="hfMenuID" Value='<%#
Eval("MenuID") %>' runat="server" />
<asp:HiddenField ID="hfName" Value='<%#
Eval("HeaderID") %>' runat="server" />
</td>
<td>
<asp:CheckBox ID="chkRead" runat="server"
AutoPostBack="true" Checked="true" CausesValidation="false"
OnCheckedChanged="chkRead_CheckedChanged"></asp:CheckBox>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
change your checkbox property to
<asp:CheckBox ID="chkSubModuleView"
Checked="true" runat="server" AutoPostBack="true" Key='<%# Eval("ID")%>'
OnCheckedChanged="chkSubModuleView_CheckedChanged" />
In your .cs
protected void chkSubModuleView_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
string yourID = chk.Attributes["Key"].ToString();
}
I am having 5 div tags,in each div tag I am having repeater control.I want to allow user update information if he want.So on form load,I am retrieving all information from table,so one can update information.But I am unable to do this.I am giving the code for 3 repeater control.I tried this on button update click.Problem is when i clicked on update button it is not loop through first 4 repeater's for each loop,it just loop through the last for each loop.And I have created store procedure to update information.So,I want to send all parameters to it like:
enter code here
ob.UpdateProfile(profileid, candiid, pheadline, ethnicity, religion, caste, starsign, purpose, maritalstatus, lang, htid, height, wt, skincolor, eyesight, abtme, diet, drink, smoking, drug, frndship, schoolname, schpassyr, collegename, collgpassyr, compwebsite);
enter code here
foreach (RepeaterItem repItem in repProfileInfo.Items)
{
TextBox tProfileHeadline = repItem.FindControl("txtProfileHeadline") as TextBox;
pheadline = tProfileHeadline.Text;
DropDownList ddlEthnicity = repItem.FindControl("drpEthnicity") as DropDownList;
ethnicity = ddlEthnicity.SelectedItem.Text;
DropDownList ddlReligion = repItem.FindControl("drpReligion") as DropDownList;
religion = ddlReligion.SelectedItem.Text;
TextBox tCaste = repItem.FindControl("txtCaste") as TextBox;
caste = tCaste.Text;
DropDownList ddlStarSign = repItem.FindControl("drpStarSign") as DropDownList;
starsign = ddlStarSign.SelectedItem.Text;
DropDownList ddlPurpose = repItem.FindControl("drpPurpose") as DropDownList;
purpose = ddlPurpose.SelectedItem.Text;
DropDownList ddlMaritalStatus = repItem.FindControl("drpMaritalStatus") as DropDownList;
maritalstatus = ddlMaritalStatus.SelectedItem.Text;
TextBox tLanguage = repItem.FindControl("txtLanguage") as TextBox;
lang = tLanguage.Text;
TextBox tSchoolName = repItem.FindControl("txtSchoolName") as TextBox;
schoolname = tSchoolName.Text;
DropDownList ddlSchoolPassYr = repItem.FindControl("drpSchoolPassYr") as DropDownList;
schpassyr = ddlSchoolPassYr.SelectedItem.Text;
TextBox tCollegeName = repItem.FindControl("txtCollegeName") as TextBox;
collegename = tCollegeName.Text;
DropDownList ddlCollegePassYr = repItem.FindControl("drpCollegePassYr") as DropDownList;
collgpassyr = ddlCollegePassYr.SelectedItem.Text;
TextBox tCompanyWebsite = repItem.FindControl("txtCompanyWebsite") as TextBox;
compwebsite = tCompanyWebsite.Text;
}
foreach(RepeaterItem repItem1 in repPhysicalInfo.Items)
{
DropDownList ddlHeight = repItem1.FindControl("drpHeight") as DropDownList;
htid =ddlHeight.SelectedValue;
height = ddlHeight.SelectedItem.Text;
TextBox tWeight = repItem1.FindControl("txtWeight") as TextBox;
wt = tWeight.Text;
DropDownList ddlSkinColor = repItem1.FindControl("drpSkinColor") as DropDownList;
skincolor = ddlSkinColor.SelectedItem.Text;
DropDownList ddlEyeSight = repItem1.FindControl("drpEyeSight") as DropDownList;
eyesight = ddlEyeSight.SelectedItem.Text;
}
foreach(RepeaterItem repItem2 in repAbootMe.Items)
{
TextBox tAboutMe = repItem2.FindControl("txtAboutMe") as TextBox;
abtme = tAboutMe.Text;
CheckBox chkFriendShip = repItem2.FindControl("chkActivateFriendship") as CheckBox;
if (chkFriendShip.Checked == true)
frndship = "Yes";
else
frndship = "No";
}
As it is loop through the last for each loop,I am getting error in procedure,as it is not getting all its parameter.Variables I defined in first 4 repeater control loop,getting null value.So I want know how I can get information in all repeater controls,so i can update it.Give me any solution for this.Thanks in advance.
Design code of web form:
Height:
' Width="150px">
4.10
4.11
5.0
5.1
5.2
5.3
5.4
5.5
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Weight
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtWeight" runat="server" Text='<%#Eval("wt") %>' Width="150px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Skin Color:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtSkinColor" runat="server" Text='<%#Eval("skincolor")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpSkinColor" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem>Wheatish</asp:ListItem>
<asp:ListItem>Fair</asp:ListItem>
<asp:ListItem>Tan/Brown</asp:ListItem>
<asp:ListItem>Dark</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Eye Sight:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtEyeSight" runat="server" Text='<%#Eval("eyesight")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpEyeSight" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem>Clear</asp:ListItem>
<asp:ListItem>Glasses</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</div>
<div id="aboutMe" runat="server" visible="false" style="margin-left: 50px; display: block">
<asp:Repeater ID="repAbootMe" runat="server" OnItemDataBound="myAboutMe">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="directorytdWidth">
About Me:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtAboutMe" runat="server" Text='<%#Eval("aboutMe")%>' Width="200px"
TextMode="MultiLine" Height="100px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Active Friendship Zone:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtActiveFrndZone" runat="server" Text='<%#Eval("friendship")%>'
Width="100px"></asp:TextBox>
<asp:CheckBox ID="chkActivateFriendship" runat="server" Text="Activate My Friendship Zone Profile"
Checked="True" ForeColor="#000000" Visible="false" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
<div id="otherInfo" runat="server" visible="false" style="margin-left: 50px; display: block">
<asp:Repeater ID="repOtherInfo" runat="server" OnItemDataBound="myOtherInfo">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="directorytdWidth">
Diet:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDiet" runat="server" Text='<%#Eval("diet")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpDiet" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Veg</asp:ListItem>
<asp:ListItem>Non-Veg</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Drink:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDrink" runat="server" Text='<%#Eval("drink")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpDrinks" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Don't Drink</asp:ListItem>
<asp:ListItem>Drink Socially</asp:ListItem>
<asp:ListItem>Drink like fish</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Smoke:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtSmoke" runat="server" Text='<%#Eval("smoke")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpSmoking" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Don't Smoke</asp:ListItem>
<asp:ListItem>Smoke Socially</asp:ListItem>
<asp:ListItem>Smoker</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Drugs:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDrug" runat="server" Text='<%#Eval("drug")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpDrug" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>No Drugs</asp:ListItem>
<asp:ListItem>Druggi</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</div>
<div id="contactInfo" runat="server" visible="false" style="margin-left: 50px; display: block">
<asp:Repeater ID="repContactInfo" runat="server" OnItemDataBound="myContactInfo">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="directorytdWidth">
First Name:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtFirstName" runat="server" Width="150px" Text='<%#Eval("firstName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Last Name:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtLastName" runat="server" Width="150px" Text='<%#Eval("lastName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Gender:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtGender" runat="server" Width="100px" Text='<%#Eval("gender")%>'></asp:TextBox>
<asp:RadioButtonList ID="radioGender" runat="server" RepeatColumns="2" Visible="false">
<asp:ListItem Text="Male" Value="M"></asp:ListItem>
<asp:ListItem Text="Female" Value="F"> </asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Address:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtAdd" runat="server" Width="200px" Text='<%#Eval("candiAddress")%>'
TextMode="MultiLine" Height="75px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Country:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCountry" runat="server" Width="150px" Text='<%#Eval("countryName")%>'></asp:TextBox>
<asp:DropDownList ID="drpCountry" runat="server" Width="150px" Height="24px" Visible="false"
AutoPostBack="true" OnSelectedIndexChanged="drpCountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
State:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtState" runat="server" Width="150px" Text='<%#Eval("stateName")%>'></asp:TextBox>
<asp:DropDownList ID="drpState" runat="server" Width="150px" Visible="false" Height="24px"
AutoPostBack="true" OnSelectedIndexChanged="drpState_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
City:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCity" runat="server" Width="150px" Text='<%#Eval("cityName")%>'></asp:TextBox>
<asp:DropDownList ID="drpCity" runat="server" Width="150px" Height="24px" Visible="false"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Postal Code:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtPostalCode" runat="server" Width="150px" Text='<%#Eval("pincode")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Landline:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtLandline" runat="server" Width="150px" Text='<%#Eval("landline")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Mobile Number:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtMobile" runat="server" Width="150px" Text='<%#Eval("mobile")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Date of Birth:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDob" runat="server" Width="150px" Text='<%#Eval("dob")%>'></asp:TextBox>
<asp:DropDownList ID="drpYear" runat="server" Visible="false" Height="24px" Width="80px"
AutoPostBack="true">
</asp:DropDownList>
<asp:DropDownList ID="drpMonth" runat="server" Height="24px" Width="80px" OnSelectedIndexChanged="drpMonth_SelectedIndexChanged"
AutoPostBack="true" Visible="false">
<asp:ListItem Value="1" Selected="True">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="drpDate" runat="server" Height="24px" Width="50px" Visible="false"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Email Address:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtEmail" runat="server" Width="150px" Text='<%#Eval("altEmail")%>'></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</div>
<div style="text-align: center">
<asp:Button ID="btnUpdate" Text="Update" runat="server" CssClass="btnImage" OnClick="btnUpdate_Click" /></div>
</div>
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 have a formview with several data items that works perfectly except for a single parameter that will not update with the rest of them. The formview's datasource updateparameter is set to do nothing so that I can handle the update in codebehind. Every item works fine, except for one parameter ("salesprice") that is missing in the OldValues and NewValues argument of the ItemUpdating event of the formview. The data DOES pull in to the textbox as it should, formatted properly and all.
I've attached the html, SQL (for getLoanData()), and the codebehind.
Why would every parameter exist in the New/OldValue arguments except the "salesprice" parameter? I've tried populating the textbox without the formatstring, and it's still missing. Is there something about a money SQL datatype that might cause a problem?
HTML:
<asp:FormView ID="fvLoanDetails" runat="server" DataKeyNames="orderid"
DataSourceID="sqlLoanDetails" Width="100%">
<ItemTemplate>
...
</ItemTemplate>
<EditItemTemplate>
<table class="orderSectionHeader">
<tr>
<td style="padding-left:10px;">
<h2>Loan Details</h2>
</td>
<td style="text-align:right;">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
<asp:Button ID="bvnSave" runat="server" Text="Save" CommandName="Update" />
</td>
</tr>
</table>
<table class="orderSection">
<tr>
<td class="orderHeader" style="vertical-align:top;">
Loan Number
</td>
<td>
<asp:Label ID="lblLoanNumber" CssClass="orderData" runat="server"
Text='<%# Bind("loannumber") %>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Business Channel
</td>
<td>
<asp:DropDownList ID="ddlBusinessChannel" runat="server"
DataSourceID="sqlBusinessChannels" DataTextField="BusinessChannel"
DataValueField="BusinessChannel" SelectedValue='<%# Bind("businesschannel") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="sqlBusinessChannels" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="SELECT DISTINCT [BusinessChannel] FROM [Loans] ORDER BY [BusinessChannel]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="orderHeader">
Loan Type
</td>
<td>
<asp:DropDownList ID="ddlLoanType" runat="server"
DataSourceID="sqlLoanType" DataTextField="LoanType"
DataValueField="LoanType" SelectedValue='<%# Bind("loantype") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="sqlLoanType" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="SELECT DISTINCT [LoanType] FROM [Loans] ORDER BY [LoanType]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="orderHeader">
Purpose
</td>
<td>
<asp:DropDownList ID="ddlPurpose" runat="server"
SelectedValue='<%# Bind("purpose") %>'>
<asp:ListItem Text="Purchase" Value="False" />
<asp:ListItem Text="Refinance" Value="True" />
</asp:DropDownList>
</td>
</tr>
<tr id="trSalesPrice" runat="server">
<td class="orderHeader">
Sales Price
</td>
<td>
<asp:TextBox ID="txtSalesPrice" CssClass="orderData" runat="server" Width="100"
Text='<%# Bind("salesprice", "{0:F2}") %>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower
</td>
<td>
<table cellspacing="0">
<tr style="font-size:8pt;padding-bottom:0px;">
<td>First</td><td>Last</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtBFirst" CssClass="orderData" runat="server" Width="80"
Text='<%# Bind("firstname") %>' />
</td>
<td>
<asp:TextBox ID="txtBLast" CssClass="orderData" runat="server" Width="120"
Text='<%# Bind("lastname") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Email
</td>
<td>
<asp:TextBox ID="txtEmail" CssClass="orderData" runat="server" Width="200"
Text='<%# Bind("email") %>' />
</td>
</tr>
<tr>
<td class="orderHeader" style="vertical-align:top;">
Mailing Address
</td>
<td>
<table cellspacing="0">
<tr style="font-size:8pt;padding-bottom:0px;">
<td colspan="3">Address</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="txtAddress" CssClass="orderData" runat="server" Width="200"
Text='<%# Bind("address") %>' />
</td>
</tr>
<tr style="font-size:8pt;padding-bottom:0px;">
<td>City</td><td>State</td><td>Zip</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCity" CssClass="orderData" runat="server" Width="100"
Text='<%# Bind("city") %>' />
</td>
<td>
<asp:TextBox ID="txtState" CssClass="orderData" runat="server" Width="30"
Text='<%# Bind("state") %>' />
</td>
<td>
<asp:TextBox ID="txtZip" CssClass="orderData" runat="server" Width="50"
Text='<%# Bind("zip") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Primary
</td>
<td>
<asp:TextBox ID="txtBPhone" CssClass="orderData" runat="server"
Text='<%# Bind("phone1", "{0:(###) ###-####}")%>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Secondary
</td>
<td>
<asp:TextBox ID="txtBCell" CssClass="orderData" runat="server"
Text='<%# Bind("phone2", "{0:(###) ###-####}")%>' />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sqlLoanDetails" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="select #orderid as orderid, * from dbo.getLoanData(#orderid)"
UpdateCommand="select #orderid">
<SelectParameters>
<asp:ControlParameter ControlID="hdnOrderID" Name="orderid"
PropertyName="Value" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
VB.NET:
Protected Sub fvLoanDetails_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles fvLoanDetails.ItemUpdating
Dim o As Order = DAL.GetOrderById(hdnOrderID.Value)
Dim l As Loan = DAL.GetLoanByLoanID(o.LoanID)
Dim b As Contact = DAL.GetContactById(l.BorrowerContactID)
l.BusinessChannel = e.NewValues("businesschannel")
l.LoanType = e.NewValues("loantype")
l.Purpose = e.NewValues("purpose")
l.SalesPrice = e.NewValues("salesprice")
DAL.UpdateLoan(l)
b.FirstName = e.NewValues("firstname")
b.LastName = e.NewValues("lastname")
b.Address = e.NewValues("address")
b.City = e.NewValues("city")
b.State = e.NewValues("state")
b.Zip = e.NewValues("zip")
b.Phone = e.NewValues("phone1")
b.Cell = e.NewValues("phone2")
DAL.UpdateContact(b)
End Sub
SQL:
select
l.loannumber, l.businesschannel, l.loantype, l.purpose, l.salesprice, b.firstname, b.lastname, b.email,
b.address, b.city, b.state, b.zip, b.phone as phone1, b.cell as phone2,
dbo.formataddressweb(b.address, '', b.city, b.state, b.zip) as mailingaddress from loans l
join orders o on o.orderid=#orderid
join contacts b on l.borrowercontactid=b.contactid
where l.loanid=(select loanid from orders where orderid=#orderid)
Have you tried a different format string?
Text='<%# Bind("salesprice", "{0:C}") %>'