I have a listview that is connected to sqlserver but the columns of listview are shown without any white space in-between. I want to add a feature like cellpadding in table to my Listview.
My code :
<asp:ListView ID="ListView1" runat="server" DataKeyNames="DarkhastId"
DataSourceID="SqlDataSource1" GroupItemCount="2">
<AlternatingItemTemplate>
<td runat="server" style="">
DarkhastId:
<asp:Label ID="DarkhastIdLabel" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
shakhs:
<asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
<br />
nam:
<asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
<br />
Idgharardad:
<asp:Label ID="IdgharardadLabel" runat="server"
Text='<%# Eval("Idgharardad") %>' />
<br />
elat:
<asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
<br />
hamrah:
<asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
<br />
sabet:
<asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
<br />
vaziat:
<asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
<br />
karshenas:
<asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
<br />
tarikh:
<asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</AlternatingItemTemplate>
<EditItemTemplate>
<td runat="server" style="">
DarkhastId:
<asp:Label ID="DarkhastIdLabel1" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
shakhs:
<asp:TextBox ID="shakhsTextBox" runat="server" Text='<%# Bind("shakhs") %>' />
<br />
nam:
<asp:TextBox ID="namTextBox" runat="server" Text='<%# Bind("nam") %>' />
<br />
Idgharardad:
<asp:TextBox ID="IdgharardadTextBox" runat="server"
Text='<%# Bind("Idgharardad") %>' />
<br />
elat:
<asp:TextBox ID="elatTextBox" runat="server" Text='<%# Bind("elat") %>' />
<br />
hamrah:
<asp:TextBox ID="hamrahTextBox" runat="server" Text='<%# Bind("hamrah") %>' />
<br />
sabet:
<asp:TextBox ID="sabetTextBox" runat="server" Text='<%# Bind("sabet") %>' />
<br />
vaziat:
<asp:TextBox ID="vaziatTextBox" runat="server" Text='<%# Bind("vaziat") %>' />
<br />
karshenas:
<asp:TextBox ID="karshenasTextBox" runat="server"
Text='<%# Bind("karshenas") %>' />
<br />
tarikh:
<asp:TextBox ID="tarikhTextBox" runat="server" Text='<%# Bind("tarikh") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
<br />
</td>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr ID="itemPlaceholderContainer" runat="server">
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<InsertItemTemplate>
<td runat="server" style="">
shakhs:
<asp:TextBox ID="shakhsTextBox" runat="server" Text='<%# Bind("shakhs") %>' />
<br />
nam:
<asp:TextBox ID="namTextBox" runat="server" Text='<%# Bind("nam") %>' />
<br />
Idgharardad:
<asp:TextBox ID="IdgharardadTextBox" runat="server"
Text='<%# Bind("Idgharardad") %>' />
<br />
elat:
<asp:TextBox ID="elatTextBox" runat="server" Text='<%# Bind("elat") %>' />
<br />
hamrah:
<asp:TextBox ID="hamrahTextBox" runat="server" Text='<%# Bind("hamrah") %>' />
<br />
sabet:
<asp:TextBox ID="sabetTextBox" runat="server" Text='<%# Bind("sabet") %>' />
<br />
vaziat:
<asp:TextBox ID="vaziatTextBox" runat="server" Text='<%# Bind("vaziat") %>' />
<br />
karshenas:
<asp:TextBox ID="karshenasTextBox" runat="server"
Text='<%# Bind("karshenas") %>' />
<br />
tarikh:
<asp:TextBox ID="tarikhTextBox" runat="server" Text='<%# Bind("tarikh") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
<br />
</td>
</InsertItemTemplate>
<ItemTemplate>
<td runat="server" style="">
DarkhastId:
<asp:Label ID="DarkhastIdLabel" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
shakhs:
<asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
<br />
nam:
<asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
<br />
Idgharardad:
<asp:Label ID="IdgharardadLabel" runat="server"
Text='<%# Eval("Idgharardad") %>' />
<br />
elat:
<asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
<br />
hamrah:
<asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
<br />
sabet:
<asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
<br />
vaziat:
<asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
<br />
karshenas:
<asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
<br />
tarikh:
<asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="groupPlaceholderContainer" runat="server" border="0" style="">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server" PageSize="12">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<td runat="server" style="">
DarkhastId:
<asp:Label ID="DarkhastIdLabel" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
shakhs:
<asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
<br />
nam:
<asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
<br />
Idgharardad:
<asp:Label ID="IdgharardadLabel" runat="server"
Text='<%# Eval("Idgharardad") %>' />
<br />
elat:
<asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
<br />
hamrah:
<asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
<br />
sabet:
<asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
<br />
vaziat:
<asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
<br />
karshenas:
<asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
<br />
tarikh:
<asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:akhbarrrConnectionString %>"
DeleteCommand="DELETE FROM [darkhastezam] WHERE [DarkhastId] = #DarkhastId"
InsertCommand="INSERT INTO [darkhastezam] ([shakhs], [nam], [Idgharardad], [elat], [hamrah], [sabet], [vaziat], [karshenas], [tarikh]) VALUES (#shakhs, #nam, #Idgharardad, #elat, #hamrah, #sabet, #vaziat, #karshenas, #tarikh)"
SelectCommand="SELECT * FROM [darkhastezam]"
UpdateCommand="UPDATE [darkhastezam] SET [shakhs] = #shakhs, [nam] = #nam, [Idgharardad] = #Idgharardad, [elat] = #elat, [hamrah] = #hamrah, [sabet] = #sabet, [vaziat] = #vaziat, [karshenas] = #karshenas, [tarikh] = #tarikh WHERE [DarkhastId] = #DarkhastId">
<DeleteParameters>
<asp:Parameter Name="DarkhastId" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="shakhs" Type="String" />
<asp:Parameter Name="nam" Type="String" />
<asp:Parameter Name="Idgharardad" Type="Decimal" />
<asp:Parameter Name="elat" Type="String" />
<asp:Parameter Name="hamrah" Type="String" />
<asp:Parameter Name="sabet" Type="String" />
<asp:Parameter Name="vaziat" Type="String" />
<asp:Parameter Name="karshenas" Type="String" />
<asp:Parameter Name="tarikh" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="shakhs" Type="String" />
<asp:Parameter Name="nam" Type="String" />
<asp:Parameter Name="Idgharardad" Type="Decimal" />
<asp:Parameter Name="elat" Type="String" />
<asp:Parameter Name="hamrah" Type="String" />
<asp:Parameter Name="sabet" Type="String" />
<asp:Parameter Name="vaziat" Type="String" />
<asp:Parameter Name="karshenas" Type="String" />
<asp:Parameter Name="tarikh" Type="String" />
<asp:Parameter Name="DarkhastId" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
Can you just add the cellspacing attribute?
<LayoutTemplate>
<table runat="server" cellspacing="5">
I would suggest adding css styling:
for example this item although this is for a button:
<asp:Button ID="CancelButton" runat="server" style="padding:15px;" CommandName="Cancel" Text="Clear" />
also see http://msdn.microsoft.com/en-us/library/9wx8w7we for css classes
Add CssClass to all table tags
<table class="test" ...
Create inline style (or external). You can change the styling to margin or padding-top / padding-bottom that fits your needs.
table.test td {
padding: 3px;
}
Related
Hi I hope got my problem solved ... I have a listview which contains 2 dropdownlists, it works well in show data but when insert button clicked I got error of can't insert null values so it couldn't read my selected value of the second dropdownlist
Here is my html code
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SwProjParticpant.aspx.cs" Inherits="WebApplication1.Account.SwProjParticpant" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TDCConnectionString2 %>" SelectCommand="Select distinct * from SupervisionSoftware INNER JOIN Schools ON SupervisionSoftware.SchoolID=Schools.SchoolID INNER JOIN Projects ON Projects.ProjectID=SupervisionSoftware.ProjectID"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="PartID,ProjectID" DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="background-color: #FAFAD2;color: #284775;">
<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="PartIDLabel" runat="server" Text='<%# Eval("PartID") %>' />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="ProjectIDLabel" runat="server" Text='<%# Eval("ProjectID") %>' />
</td>
<td>
<asp:DropDownList ID="SchoolIDLabel" runat="server" DataSourceID="SqlDataSource2" DataValueField="SchoolID" DataTextField="Name" Text='<%# Eval("SchoolID") %>' Enabled="false" />
</td>
<td>
<asp:Label ID="ClassLabel" runat="server" Text='<%# Eval("Class") %>' />
</td>
<td>
<asp:Label ID="SpecializationLabel" runat="server" Text='<%# Eval("Specialization") %>' />
</td>
<td>
<asp:Label ID="TeacherCodeLabel" runat="server" Text='<%# Eval("TeacherCode") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color: #FFCC66;color: #000080;">
<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="PartIDLabel1" runat="server" Text='<%# Eval("PartID") %>' />
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:DropDownList ID="ProjectIDTextBox1" runat="server" DataSourceID="SqlDataSource2" DataValueField="ProjectID" DataTextField="ProjName" Text='<%# Bind("ProjectID") %>' AutoPostBack="true" OnSelectedIndexChanged="ProjectIDTextBox1_SelectedIndexChanged" />
</td>
<td>
<asp:DropDownList ID="SchoolIDTextBox" AutoPostBack="true" runat="server" />
</td>
<td>
<asp:TextBox ID="ClassTextBox" runat="server" Text='<%# Bind("Class") %>' />
</td>
<td>
<asp:TextBox ID="SpecializationTextBox" runat="server" Text='<%# Bind("Specialization") %>' />
</td>
<td>
<asp:TextBox ID="TeacherCodeTextBox" runat="server" Text='<%# Bind("TeacherCode") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<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="PartIDTextBox" runat="server" Text='<%# Bind("PartID") %>' />
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:DropDownList ID="ProjectIDTextBox1" runat="server" DataSourceID="SqlDataSource2" DataValueField="ProjectID" DataTextField="ProjName" Text='<%# Bind("ProjectID") %>' AutoPostBack="true" OnSelectedIndexChanged="ProjectIDTextBox1_SelectedIndexChanged" />
</td>
<td>
<asp:DropDownList ID="SchoolIDTextBox" AutoPostBack="true" runat="server" />
</td>
<td>
<asp:TextBox ID="ClassTextBox" runat="server" Text='<%# Bind("Class") %>' />
</td>
<td>
<asp:TextBox ID="SpecializationTextBox" runat="server" Text='<%# Bind("Specialization") %>' />
</td>
<td>
<asp:TextBox ID="TeacherCodeTextBox" runat="server" Text='<%# Bind("TeacherCode") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color: #FFFBD6;color: #333333;">
<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="PartIDLabel" runat="server" Text='<%# Eval("PartID") %>' />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="ProjectIDLabel" runat="server" Text='<%# Eval("ProjectID") %>' />
</td>
<td>
<asp:DropDownList ID="SchoolIDLabel" runat="server" DataSourceID="SqlDataSource2" DataValueField="SchoolID" DataTextField="Name" Text='<%# Eval("SchoolID") %>' Enabled="false" />
</td>
<td>
<asp:Label ID="ClassLabel" runat="server" Text='<%# Eval("Class") %>' />
</td>
<td>
<asp:Label ID="SpecializationLabel" runat="server" Text='<%# Eval("Specialization") %>' />
</td>
<td>
<asp:Label ID="TeacherCodeLabel" runat="server" Text='<%# Eval("TeacherCode") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color: #FFFBD6;color: #333333;">
<th runat="server"></th>
<th runat="server">PartID</th>
<th runat="server">Name</th>
<th runat="server">ProjectID</th>
<th runat="server">SchoolID</th>
<th runat="server">Class</th>
<th runat="server">Specialization</th>
<th runat="server">TeacherCode</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color: #FFCC66;font-weight: bold;color: #000080;">
<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="PartIDLabel" runat="server" Text='<%# Eval("PartID") %>' />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="ProjectIDLabel" runat="server" Text='<%# Eval("ProjectID") %>' />
</td>
<td>
<asp:DropDownList ID="SchoolIDLabel" runat="server" DataSourceID="SqlDataSource2" DataValueField="SchoolID" DataTextField="Name" Text='<%# Eval("SchoolID") %>' Enabled="false" />
</td>
<td>
<asp:Label ID="ClassLabel" runat="server" Text='<%# Eval("Class") %>' />
</td>
<td>
<asp:Label ID="SpecializationLabel" runat="server" Text='<%# Eval("Specialization") %>' />
</td>
<td>
<asp:Label ID="TeacherCodeLabel" runat="server" Text='<%# Eval("TeacherCode") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:TDCConnectionString2 %>" DeleteCommand="DELETE FROM [SWprjectPart] WHERE [PartID] = #original_PartID AND [ProjectID] = #original_ProjectID AND [Name] = #original_Name AND [SchoolID] = #original_SchoolID AND [Class] = #original_Class AND [Specialization] = #original_Specialization AND [TeacherCode] = #original_TeacherCode" InsertCommand="INSERT INTO [SWprjectPart] ([PartID], [Name], [ProjectID], [SchoolID], [Class], [Specialization], [TeacherCode]) VALUES (#PartID, #Name, #ProjectID, #SchoolID, #Class, #Specialization, #TeacherCode)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [SWprjectPart]" UpdateCommand="UPDATE [SWprjectPart] SET [Name] = #Name, [SchoolID] = #SchoolID, [Class] = #Class, [Specialization] = #Specialization, [TeacherCode] = #TeacherCode WHERE [PartID] = #original_PartID AND [ProjectID] = #original_ProjectID AND [Name] = #original_Name AND [SchoolID] = #original_SchoolID AND [Class] = #original_Class AND [Specialization] = #original_Specialization AND [TeacherCode] = #original_TeacherCode">
<DeleteParameters>
<asp:Parameter Name="original_PartID" Type="Int32" />
<asp:Parameter Name="original_ProjectID" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_SchoolID" Type="Int32" />
<asp:Parameter Name="original_Class" Type="String" />
<asp:Parameter Name="original_Specialization" Type="String" />
<asp:Parameter Name="original_TeacherCode" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PartID" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ProjectID" Type="Int32" />
<%--<asp:ControlParameter Name="SchoolID" ControlId="ListView1$SchoolIDTextBox" PropertyName="SelectedValue" Type="String" />--%>
<asp:Parameter Name="SchoolID" Type="Int32" />
<asp:Parameter Name="Class" Type="String" />
<asp:Parameter Name="Specialization" Type="String" />
<asp:Parameter Name="TeacherCode" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="SchoolID" Type="Int32" />
<asp:Parameter Name="Class" Type="String" />
<asp:Parameter Name="Specialization" Type="String" />
<asp:Parameter Name="TeacherCode" Type="Int32" />
<asp:Parameter Name="original_PartID" Type="Int32" />
<asp:Parameter Name="original_ProjectID" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_SchoolID" Type="Int32" />
<asp:Parameter Name="original_Class" Type="String" />
<asp:Parameter Name="original_Specialization" Type="String" />
<asp:Parameter Name="original_TeacherCode" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
and here my code behind
protected void ProjectIDTextBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string strConnection = null;
strConnection = "Data Source=DESKTOP-HJRRBDG;Initial Catalog=TDC;Integrated Security=True";
DropDownList ddlListFind = (DropDownList)sender;
ListViewItem item1 = (ListViewItem)ddlListFind.NamingContainer;
DropDownList getDDLList = (DropDownList)item1.FindControl("ProjectIDTextBox1");
DropDownList schoolbox = (DropDownList)item1.FindControl("SchoolIDTextBox");
int ProjectID = Convert.ToInt32(getDDLList.SelectedValue);
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select distinct * from SupervisionSoftware inner join Schools On SupervisionSoftware.SchoolID = Schools.SchoolID where ProjectID=" + ProjectID, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
schoolbox.DataSource = ds;
schoolbox.DataTextField = "Name";
schoolbox.DataValueField = "SchoolID";
schoolbox.DataBind();
con.Close();
please could anyone help me ?
Kindly share your error here it looks like you are not properly select values when going to insert.
The best practice is whenever this type of issue rises use a debugger before you are going to select or insert value so you are sure about fetching values proper or not.
I want to bind a image (which is stored in binary format column name image(varbinary)) in list view in c#..
i am trying this two but not working..
<img src='<%# string.Format("data:image/gif;base64,{0}",Convert.ToBase64String((byte[])Eval("image")))%>'/>--%>
<%--<asp:Image ID="Image10" runat="server" Height="100px" ImageUrl='<%# "ShowImage.ashx?id=" + Eval("image") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("image")) %>' />--%>
here is the code:
<div>
<h3 class="calDetail">Event Details</h3>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:VeteransDirectoryConnectionString %>" SelectCommand=
"SELECT [EventID], [OrganizationName], [Title], [DescriptionShort], [DescriptionLong], [Location], [EventDate], [URL], (CASE WHEN URL IS NULL OR URL = '' THEN CAST(0 AS bit) ELSE CAST(1 AS bit) END) AS URLLink, [FileName], (CASE WHEN FileName IS NULL OR FileName = '' THEN CAST(0 AS bit) ELSE CAST(1 AS bit) END) AS FileLink, [EventTime],image FROM [t_Event] WHERE ([EventID] = #EventID)">
<SelectParameters>
<asp:QueryStringParameter Name="EventID" QueryStringField="eventid" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<div style="padding: 0px 10px 20px 10px;">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="EventID" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
<span>No data for this event was found.</span>
</EmptyDataTemplate>
<ItemTemplate>
<span class="listCalLabel">Organization:</span>
<asp:Label ID="OrganizationNameLabel" runat="server" Text='<%# Eval("OrganizationName") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel">Event:</span>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel">Short Description:</span>
<asp:Label ID="DescriptionShortLabel" runat="server" Text='<%# Eval("DescriptionShort") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel">Long Description:</span>
<asp:Label ID="DescriptionLongLabel" runat="server" Text='<%# Eval("DescriptionLong") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel">Location:</span>
<asp:Label ID="LocationLabel" runat="server" Text='<%# Eval("Location") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel">Event Date:</span>
<asp:Label ID="EventDateLabel" runat="server" Text='<%# Eval("EventDate", "{0:MM/dd/yyyy}") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel">Event Time:</span>
<asp:Label ID="EventTimeLabel" runat="server" Text='<%# Eval("EventTime") %>' CssClass="listCalText" />
<br /><br />
<span class="listCalLabel"><asp:Label ID="lblURL" runat="server" Visible='<%# Eval("URLLink") %>' Text="Additional Info (website):" ></asp:Label></span>
<br />
<asp:HyperLink ID="URLHyperLink" runat="server" Text='<%# Eval("URL") %>' NavigateUrl='<%# Eval("URL") %>' Visible='<%# Eval("URLLink") %>' Target="_blank" CssClass="listLink" />
<br /><br />
<span class="listCalLabel"><asp:Label ID="lblFile" runat="server" Visible='<%# Eval("FileLink") %>' Text="Additional Info (file):"></asp:Label></span>
<br />
<asp:HyperLink ID="URLFile" runat="server" Text='<%# Eval("FileName") %>' NavigateUrl='<%# "EventFiles/" + Eval("FileName") %>' Visible='<%# Eval("FileLink") %>' Target="_blank" CssClass="listLink" />
<br /><br />
<%-- <img src='<%# string.Format("data:image/gif;base64,{0}",Convert.ToBase64String((byte[])Eval("image")))%>'/>--%>
<%--<asp:Image ID="Image10" runat="server" Height="100px" ImageUrl='<%# "ShowImage.ashx?id=" + Eval("image") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("image")) %>' />--%>
<br /></span>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
<asp:Button ID="btnOK" runat="server" OnClientClick="window.close(); return false;" Text="Close Event Detail" CssClass="btn btn-default" />
<br />
<br />
</div>
</div>
what should i do???
how to retrieve the image and show ina a webform ??
You can use handler to display image in gridview , your html markup look like inside
Gridview ItemTemplate set image control src as src=~/getImage.ashx?id=" + id
where getImage.ashx is your handler which return MemoryStream((byte[])img);
for more details read http://www.aspdotnet-suresh.com/2015/07/save-retrieve-display-binary-images-in-gridview-from-database-in-aspnet-csharp-vbnet.html
In my .aspx page I have the following code in my ListView control;
<%# Page Title="User Registration" MasterPageFile="MasterPage.master" Language="C#" AutoEventWireup="true" CodeFile="registration.aspx.cs" Inherits="registration" %>
<asp:Content ContentPlaceHolderID="head" Runat="Server">
<!-- Your Code goes here -->
</asp:Content>
<asp:Content ContentPlaceHolderID="menu" Runat="Server">
<!-- Your Code goes here -->
</asp:Content>
<asp:Content ContentPlaceHolderID="main_content" Runat="Server">
<div class="row">
<div class="col-12">
<asp:Label Visible="false" ID="username" runat="server" Text=""></asp:Label>
<asp:sqldatasource ID="semester1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT modules.cats_points, modules.module_id, modules.compulsory, modules.module_name, modules.year FROM Courses INNER JOIN courses_vs_modules ON Courses.course_id = courses_vs_modules.course_id INNER JOIN modules ON courses_vs_modules.module_id = modules.module_id INNER JOIN student_records ON Courses.course_id = student_records.course_id AND modules.year = student_records.year AND courses_vs_modules.course_id = student_records.course_id WHERE (student_records.user_id = #user_id) AND (modules.semester = 1)"
InsertCommand="INSERT INTO [students_vs_modules]([user_id], [module_id]) VALUES (#user_id, #module_id)">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="user_id" Name="user_id" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="user_id" Type="Int32" />
<asp:Parameter Name="module_id" Type="Int32" />
</InsertParameters>
</asp:sqldatasource>
<asp:sqldatasource ID="semester2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT modules.cats_points, modules.module_id, modules.compulsory, modules.module_name, modules.year FROM Courses INNER JOIN courses_vs_modules ON Courses.course_id = courses_vs_modules.course_id INNER JOIN modules ON courses_vs_modules.module_id = modules.module_id INNER JOIN student_records ON Courses.course_id = student_records.course_id AND modules.year = student_records.year AND courses_vs_modules.course_id = student_records.course_id WHERE (student_records.user_id = #user_id) AND (modules.semester = 2)"
InsertCommand="INSERT INTO [students_vs_modules]([user_id], [module_id]) VALUES (#user_id, #module_id)">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="user_id" Name="user_id" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="user_id" Type="Int32" />
<asp:Parameter Name="module_id" Type="Int32" />
</InsertParameters>
</asp:sqldatasource>
<asp:SqlDataSource ID="emergency_contact" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT student_records.user_id, student_records.f_name, student_records.l_name, emergency_contact.em_contact_id, emergency_contact.relationship_id, emergency_contact.contact_name, emergency_contact.phone_number, emergency_contact.address_1, emergency_contact.address_2, emergency_contact.town_city, emergency_contact.county, emergency_contact.postcode, emergency_contact.country, relationship.relationship FROM student_records INNER JOIN emergency_contact ON student_records.user_id = emergency_contact.user_id INNER JOIN relationship ON emergency_contact.relationship_id = relationship.relationship_id WHERE (student_records.user_id = #user_id)"
UpdateCommand="UPDATE [emergency_contact] SET [relationship_id]=#relationship_id, [contact_name]=#contact_name, [phone_number]=#phone_number, [address_1]=#address_1, [address_2]=#address_2, [town_city]=#town_city, [county]=#county, [postcode]=#postcode, [country]=#country WHERE [user_id]=#user_id ">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="user_id" Name="user_id" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="relationship_id" Type="Int32" />
<asp:Parameter Name="contact_name" Type="String" />
<asp:Parameter Name="phone_number" Type="String" />
<asp:Parameter Name="address_1" Type="String" />
<asp:Parameter Name="address_2" Type="String" />
<asp:Parameter Name="town_city" Type="String" />
<asp:Parameter Name="county" Type="String" />
<asp:Parameter Name="postcode" Type="String" />
<asp:Parameter Name="country" Type="String" />
<asp:Parameter Name="user_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="emergency_contact_list" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT relationship_id, relationship FROM relationship"></asp:SqlDataSource>
<asp:MultiView ID="MultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="em_contact_view" runat="server">
<h1>Emergency Contact</h1>
<asp:ListView ID="em_contact_list" runat="server" DataSourceID="emergency_contact" >
<EditItemTemplate>
<span style="">user_id:
<asp:TextBox Text='<%# Bind("user_id") %>' runat="server" ID="user_idTextBox" /><br />
f_name:
<asp:TextBox Text='<%# Bind("f_name") %>' runat="server" ID="f_nameTextBox" /><br />
l_name:
<asp:TextBox Text='<%# Bind("l_name") %>' runat="server" ID="l_nameTextBox" /><br />
em_contact_id:
<asp:Label Text='<%# Eval("em_contact_id") %>' runat="server" ID="em_contact_idLabel1" /><br />
relationship_id:
<asp:TextBox Text='<%# Bind("relationship_id") %>' runat="server" ID="relationship_idTextBox" /><br />
contact_name:
<asp:TextBox Text='<%# Bind("contact_name") %>' runat="server" ID="contact_nameTextBox" /><br />
phone_number:
<asp:TextBox Text='<%# Bind("phone_number") %>' runat="server" ID="phone_numberTextBox" /><br />
address_1:
<asp:TextBox Text='<%# Bind("address_1") %>' runat="server" ID="address_1TextBox" /><br />
address_2:
<asp:TextBox Text='<%# Bind("address_2") %>' runat="server" ID="address_2TextBox" /><br />
town_city:
<asp:TextBox Text='<%# Bind("town_city") %>' runat="server" ID="town_cityTextBox" /><br />
county:
<asp:TextBox Text='<%# Bind("county") %>' runat="server" ID="countyTextBox" /><br />
postcode:
<asp:TextBox Text='<%# Bind("postcode") %>' runat="server" ID="postcodeTextBox" /><br />
country:
<asp:TextBox Text='<%# Bind("country") %>' runat="server" ID="countryTextBox" /><br />
relationship:
<asp:TextBox Text='<%# Bind("relationship") %>' runat="server" ID="relationshipTextBox" /><br />
<asp:Button runat="server" CommandName="Update" Text="Update" ID="UpdateButton" />
<asp:Button runat="server" CommandName="Cancel" Text="Cancel" ID="CancelButton" /><br />
<br />
</span>
</EditItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">user_id:
<asp:TextBox Text='<%# Bind("user_id") %>' runat="server" ID="user_idTextBox" /><br />
f_name:
<asp:TextBox Text='<%# Bind("f_name") %>' runat="server" ID="f_nameTextBox" /><br />
l_name:
<asp:TextBox Text='<%# Bind("l_name") %>' runat="server" ID="l_nameTextBox" /><br />
relationship_id:
<asp:TextBox Text='<%# Bind("relationship_id") %>' runat="server" ID="relationship_idTextBox" /><br />
contact_name:
<asp:TextBox Text='<%# Bind("contact_name") %>' runat="server" ID="contact_nameTextBox" /><br />
phone_number:
<asp:TextBox Text='<%# Bind("phone_number") %>' runat="server" ID="phone_numberTextBox" /><br />
address_1:
<asp:TextBox Text='<%# Bind("address_1") %>' runat="server" ID="address_1TextBox" /><br />
address_2:
<asp:TextBox Text='<%# Bind("address_2") %>' runat="server" ID="address_2TextBox" /><br />
town_city:
<asp:TextBox Text='<%# Bind("town_city") %>' runat="server" ID="town_cityTextBox" /><br />
county:
<asp:TextBox Text='<%# Bind("county") %>' runat="server" ID="countyTextBox" /><br />
postcode:
<asp:TextBox Text='<%# Bind("postcode") %>' runat="server" ID="postcodeTextBox" /><br />
country:
<asp:TextBox Text='<%# Bind("country") %>' runat="server" ID="countryTextBox" /><br />
relationship:
<asp:TextBox Text='<%# Bind("relationship") %>' runat="server" ID="relationshipTextBox" /><br />
<asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" /><asp:Button runat="server" CommandName="Cancel" Text="Clear" ID="CancelButton" /><br />
<br />
</span>
</InsertItemTemplate>
<ItemTemplate>
<span style="">user_id:
<asp:Label Text='<%# Eval("user_id") %>' runat="server" ID="user_idLabel" /><br />
f_name:
<asp:Label Text='<%# Eval("f_name") %>' runat="server" ID="f_nameLabel" /><br />
l_name:
<asp:Label Text='<%# Eval("l_name") %>' runat="server" ID="l_nameLabel" /><br />
em_contact_id:
<asp:Label Text='<%# Eval("em_contact_id") %>' runat="server" ID="em_contact_idLabel" /><br />
relationship_id:
<asp:Label Text='<%# Eval("relationship_id") %>' runat="server" ID="relationship_idLabel" /><br />
contact_name:
<asp:Label Text='<%# Eval("contact_name") %>' runat="server" ID="contact_nameLabel" /><br />
phone_number:
<asp:Label Text='<%# Eval("phone_number") %>' runat="server" ID="phone_numberLabel" /><br />
address_1:
<asp:Label Text='<%# Eval("address_1") %>' runat="server" ID="address_1Label" /><br />
address_2:
<asp:Label Text='<%# Eval("address_2") %>' runat="server" ID="address_2Label" /><br />
town_city:
<asp:Label Text='<%# Eval("town_city") %>' runat="server" ID="town_cityLabel" /><br />
county:
<asp:Label Text='<%# Eval("county") %>' runat="server" ID="countyLabel" /><br />
postcode:
<asp:Label Text='<%# Eval("postcode") %>' runat="server" ID="postcodeLabel" /><br />
country:
<asp:Label Text='<%# Eval("country") %>' runat="server" ID="countryLabel" /><br />
relationship:
<asp:Label Text='<%# Eval("relationship") %>' runat="server" ID="relationshipLabel" /><br />
<asp:Button runat="server" CommandName="Edit" Text="Edit" ID="EditButton" />
<br />
<br />
</span>
</ItemTemplate>
<LayoutTemplate>
<div runat="server" id="itemPlaceholderContainer" style=""><span runat="server" id="itemPlaceholder" /></div>
<div style="">
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<span style="">user_id:
<asp:Label Text='<%# Eval("user_id") %>' runat="server" ID="user_idLabel" /><br />
f_name:
<asp:Label Text='<%# Eval("f_name") %>' runat="server" ID="f_nameLabel" /><br />
l_name:
<asp:Label Text='<%# Eval("l_name") %>' runat="server" ID="l_nameLabel" /><br />
em_contact_id:
<asp:Label Text='<%# Eval("em_contact_id") %>' runat="server" ID="em_contact_idLabel" /><br />
relationship_id:
<asp:Label Text='<%# Eval("relationship_id") %>' runat="server" ID="relationship_idLabel" /><br />
contact_name:
<asp:Label Text='<%# Eval("contact_name") %>' runat="server" ID="contact_nameLabel" /><br />
phone_number:
<asp:Label Text='<%# Eval("phone_number") %>' runat="server" ID="phone_numberLabel" /><br />
address_1:
<asp:Label Text='<%# Eval("address_1") %>' runat="server" ID="address_1Label" /><br />
address_2:
<asp:Label Text='<%# Eval("address_2") %>' runat="server" ID="address_2Label" /><br />
town_city:
<asp:Label Text='<%# Eval("town_city") %>' runat="server" ID="town_cityLabel" /><br />
county:
<asp:Label Text='<%# Eval("county") %>' runat="server" ID="countyLabel" /><br />
postcode:
<asp:Label Text='<%# Eval("postcode") %>' runat="server" ID="postcodeLabel" /><br />
country:
<asp:Label Text='<%# Eval("country") %>' runat="server" ID="countryLabel" /><br />
relationship:
<asp:Label Text='<%# Eval("relationship") %>' runat="server" ID="relationshipLabel" /><br />
<asp:Button runat="server" CommandName="Edit" Text="Edit" ID="EditButton" />
<br />
<br />
</span>
</SelectedItemTemplate>
</asp:ListView>
<asp:Button CommandName="NextView" ID="em_contact_next" runat="server" Text="Next" />
</asp:View>
<asp:View ID="semester_1_view" runat="server">
<h1>Semester 1</h1>
<asp:DataList ID="semester_1_datalist" runat="server" DataSourceID="semester1">
<ItemTemplate>
module_name:
<asp:Label ID="module_nameLabel" runat="server" Text='<%# Eval("module_name") %>' />
<br />
year:
<asp:Label ID="yearLabel" runat="server" Text='<%# Eval("year") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<script type="text/javascript">
var limit = 3;
$(function () {
$('[id*="module_semester_1"]').on('change', function (evt) {
if ($('[id*="module_semester_1"]:checked').length > limit) {
this.checked = true;
alert('cannot select more than ' + limit);
}
});
});
</script>
<asp:CheckBoxList ID="module_semester_1" runat="server" DataSourceID="semester1" DataTextField="module_name" DataValueField="module_id" ></asp:CheckBoxList>
<asp:Button CommandName="NextView" ID="btnnext2" runat="server" Text="Next" OnClick="btnnext2_Click" />
</asp:View>
<asp:View ID="semester_2_view" runat="server">
<h1>Semester 2</h1>
<div runat="server">
<asp:CheckBoxList ID="moduleselect" runat="server" DataSourceID="semester2" DataTextField="module_name" DataValueField="module_id" ></asp:CheckBoxList>
<asp:DataList ID="semester_2_list" runat="server" DataSourceID="semester2">
<ItemTemplate>
module_name:
<asp:Label ID="module_nameLabel" runat="server" Text='<%# Eval("cats_points") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<br />
<asp:Button ID="uploadbutton" runat="server" Text="Choose Modules" OnClick="uploadbutton_Click" CssClass="submitbtn" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" CssClass="submitbtn" />
</div></asp:View></asp:MultiView>
</div>
</div>
</asp:Content>
I'm trying to update fields in the database table using C#, I have the following C# code, however I am receiving the error stating that TextBox control contact_nameTextBox does not exist in current context and I'm not sure why, any help would be greatly appreciated.
protected void em_contact_list_SelectedIndexChanged(object sender, EventArgs e)
{
string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(ConnectionString);
myConnection.Open();
string Name_data = contact_nameTextBox.Text;
Probably because you´re trying to access it from a protected void, you need to create an instace of it
protected void em_contact_list_SelectedIndexChanged(object sender, EventArgs e)
{
string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(ConnectionString);
myConnection.Open();
contact_nameTextBox.Text = new textBox();
string Name_data = contact_nameTextBox.Text;
protected void em_contact_list_SelectedIndexChanged(object sender, EventArgs e)
{
string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(ConnectionString);
myConnection.Open();
ListView parent = (ListView)sender;
if(parent != null)
var contact_nameTextBox = (TextBox)(parent.FindName("contact_nameTextBox"));
string contact_Name = contact_nameTextBox.Text;
//Your code
}
I have not tested this code, but hope with some small changes it should work.
How can i insert particular comment on particular post? (like Facebook)
i have two table in sql
wall=>wallid, username,post
post comment=>wall id,comment,comment id
when i insert wall id manually, it works fine, but i want that the wall id should be generated automatically to the post i enter comment in.
In design part
<div style="text-align: center">
<asp:TextBox ID="TextBox1" runat="server" Height="61px" TextMode="MultiLine" Width="271px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Height="37px" Text="Submit" Width="91px" OnClick="Button1_Click" />
</div>
<div>
<br />
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<div style="border: solid 2px brown; width: 400px; margin-bottom: 20px">
<span style="">Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("wallId") %>' />
<br />
post:
<asp:Label ID="postLabel" runat="server" Text='<%# Eval("post") %>' />
<br />
username:
<asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
<asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2" DataKeyNames="commentID" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel" />
<br />
wallID:<asp:Label Text='<%# Eval("wallID") %>' runat="server" ID="wallIDLabel" />
<br />
comment:<asp:Label Text='<%# Eval("comment") %>' runat="server" ID="commentLabel" />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</AlternatingItemTemplate>
<EditItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel1" />
<br />
wallID:<asp:TextBox Text='<%# Bind("wallID") %>' runat="server" ID="wallIDTextBox" />
<br />
comment:<asp:TextBox Text='<%# Bind("comment") %>' runat="server" ID="commentTextBox" />
<br />
<asp:Button runat="server" CommandName="Update" Text="Update" ID="UpdateButton" /><asp:Button runat="server" CommandName="Cancel" Text="Cancel" ID="CancelButton" /><br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</EditItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">wallID:<asp:TextBox Text='<%# Bind("wallID") %>' runat="server" ID="wallIDTextBox" />
<br />
comment:<asp:TextBox Text='<%# Bind("comment") %>' runat="server" ID="commentTextBox" />
<br />
<asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" /><asp:Button runat="server" CommandName="Cancel" Text="Clear" ID="CancelButton" /><br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</InsertItemTemplate>
<ItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel" />
<br />
wallID:<asp:Label Text='<%# Eval("wallID") %>' runat="server" ID="wallIDLabel" />
<br />
comment:<asp:Label Text='<%# Eval("comment") %>' runat="server" ID="commentLabel" />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</ItemTemplate>
<LayoutTemplate>
<div runat="server" id="itemPlaceholderContainer" style=""><span runat="server" id="itemPlaceholder" /></div>
<div style="">
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel" />
<br />
wallID:<asp:Label Text='<%# Eval("wallID") %>' runat="server" ID="wallIDLabel" />
<br />
comment:<asp:Label Text='<%# Eval("comment") %>' runat="server" ID="commentLabel" />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource runat="server" ID="SqlDataSource2" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT * FROM [postcomment]" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [postcomment] WHERE [commentID] = #original_commentID AND [wallID] = #original_wallID AND (([comment] = #original_comment) OR ([comment] IS NULL AND #original_comment IS NULL))" InsertCommand="INSERT INTO [postcomment] ([wallID], [comment]) VALUES (#wallID, #comment)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [postcomment] SET [wallID] = #wallID, [comment] = #comment WHERE [commentID] = #original_commentID AND [wallID] = #original_wallID AND (([comment] = #original_comment) OR ([comment] IS NULL AND #original_comment IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_commentID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_comment" Type="String"></asp:Parameter>
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="comment" Type="String"></asp:Parameter>
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="comment" Type="String"></asp:Parameter>
<asp:Parameter Name="original_commentID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_comment" Type="String"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT * FROM [wall]"></asp:SqlDataSource>
</div>
Your schema should look like
1. Post -> PostId,WallId,PostedBy, Post,PostedDateTime
2. Comments -> CommentId,PostId,Comments,CommentedBy,CommentedDateTime
Relaationship between Post and Wall should be 1 Wall and Many Posts that is 1:M relationship, similary for the comments, 1:M.
On Save
do the following:
Generate PostId automatically.
Send WallId from querystring or session or by any means you are identifying the friends wall. Similarly find out the current user id who owns the post and save the post and its datetime.
On comments, while saving comments, get the postid, and your own user id and leave the comment id autoincremented.
make the parameter direction as InputOutput parameter.
<asp:Parameter Name="wallID" Type="Int32" Direction="InputOutput"></asp:Parameter>
then you can use on Inserted event :
protected void ListView_Inserted(object sender, SqlDataSourceSelectingEventArgs e)
{
var wallID = e.Command.Parameters["#wallID"].Value ;
}
since you want the wallid to be automatically inserted as identity value. The you have to selected so that it you can grape it. try this
DECLARE #wallID AS INT = -1
INSERT INTO [postcomment]
([comment])
VALUES (#comment)
select #wallID =SCOPE_IDENTITY();
also it is not the ListView_Inserted event, it is the SqlDataSource2_Inserted
I set CausesValidation="false" to my cancel button,But when I click the Cancel button ,the exception(arrow) is displaying for fraction of seconds after the page loads.I tried many ways to disable by adding group name to validator and EnableClientScript property=false to validator but these couldn't help me resolve the problem. Even I checked many threads but no one give the solution.If any body came across this problem please help me.
<form id="form1" runat="server">
<div class="AdminContent">
<asp:Label ID="Label1" runat="server" CssClass="BreadcrumbActiveBig" Text="Group Membership" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:HiddenField ID="HiddenFieldProfile" runat="server" />
<asp:FormView DefaultMode="Edit" ID="FormView1" runat="server" DataSourceID="PermGroupObjectDataSource1"
OnPreRender="FormView1_PreRender">
<EditItemTemplate>
<table>
<tr>
<td align="left" colspan="3">
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" Width="67px"
CssClass="ButtonS1" />
<asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click" Text="Cancel"
CssClass="ButtonS1" CausesValidation="false" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblGrpName" runat="server" Text="Group Name:" Width="138px" />
</td>
<td>
<asp:TextBox ID="GroupNameTextBox" MaxLength="50" runat="server" Text='<%# Bind("GroupName") %>'
Width="337px" ReadOnly="false" />
<asp:RequiredFieldValidator ID="rqrgFldVldtr_GroupName" ControlToValidate="GroupNameTextBox"
Display="Dynamic" ErrorMessage="<" meta:resourcekey="RequiredFieldValidator1Resource2"
runat="server"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblGrpDescr" runat="server" Text="Group Description:" Width="138px" />
</td>
<td>
<asp:TextBox ID="GroupDescrTextBox" MaxLength="255" runat="server" Text='<%# Bind("GroupDescr") %>'
Width="337px" ReadOnly="false" />
</td>
</tr>
<tr>
<asp:Panel ID="managedByPanel" runat="server" Visible="false">
<td>
<asp:Label ID="lblManagedByDescr" runat="server" Text="Managed by:" Width="138px" />
</td>
<td>
<asp:DropDownList ID="managedByDropDownList" runat="server">
<asp:ListItem Value="0" Text="Admin" />
<asp:ListItem Value="1" Text="AP Clerk admin & Admin" />
<asp:ListItem Value="2" Text="POC admin & Admin" />
</asp:DropDownList>
</td>
</asp:Panel>
</tr>
<tr>
<asp:Panel ID="lblFilterPanel" runat="server" Visible="false">
<td>
<asp:Label ID="LabelFilter" runat="server" Text="Exclude From Document Filter" Width="150px" />
</td>
<td>
<asp:CheckBox ID="chbExcludefromDocFilter" runat="server" Checked='<%# Bind("ExcludeFromUserFilter") %>' />
</td>
</asp:Panel>
</tr>
<tr>
<td valign="top">
<asp:Label ID="lblMembers" runat="server" Text="Members:" Width="80px" />
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:ListBox ID="lbxMembers" runat="server" Style="overflow: auto; width: 500px;
height: 150px;" DataSourceID="MembersObjectDataSource1" DataTextField='ListName'
DataValueField="UName" SelectionMode="Multiple" />
<br />
<asp:ObjectDataSource ID="MembersObjectDataSource1" runat="server" DataObjectTypeName="System.Collections.Generic.List`1[[Accenture.CSTPrague.eAPI.GroupMember, eAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
SelectMethod="FetchGroupMembers" TypeName="Accenture.CSTPrague.eAPI.WebDB_Perm"
UpdateMethod="StoreGroupMembers">
<SelectParameters>
<asp:SessionParameter Name="o" SessionField="oPermGroup" Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
<asp:Button ID="btnDeleteSelected" runat="server" OnClick="btnDeleteSelected_Click"
Text="Delete Selected" Width="106px" CssClass="ButtonS1" Style="margin: 4px 0px 8px 2px;" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnDeleteSelected" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblUserName" runat="server" Text="User name:" Width="141px" />
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Panel ID="panel1" runat="server" DefaultButton="btnAdd">
<table>
<tr>
<td valign="top">
<accenture:lookupcontrol id="UserLookup" runat="server" lookupcommand="usr" maxlength="100"
validationgroup="addUser" disablevalidation="true" />
</td>
<td>
<asp:CustomValidator ID="cuvUserName" runat="server" ValidationGroup="addUser" Display="Dynamic"
ErrorMessage="<" EnableClientScript="false" OnServerValidate="cuvUserName_ServerValidate"
ControlToValidate="UserLookup" ValidateEmptyText="true" />
</td>
<td valign="top">
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="Add User" ValidationGroup="addUser"
CausesValidation="true" CssClass="ButtonS1" Style="margin: 2px 0px 8px 2px;" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr style="vertical-align: top">
<asp:Panel ID="queryConditionPanel" runat="server" Visible="false">
<td>
<asp:Label ID="lblQueryCondition" runat="server" Text="Query Condition:" Width="138px" />
</td>
<td>
<accenture:lengthlimitedmultilinetextbox id="txtQueryCondition" runat="server" text='<%# Bind("QueryCondition") %>'
style="width: 500px" textmode="MultiLine" maxlength="1000" height="100px" cssclass="txtbox" />
</td>
</asp:Panel>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
Gid:
<asp:TextBox ID="GidTextBox" runat="server" Text='<%# Bind("Gid") %>' /><br />
GroupName:
<asp:TextBox ID="GroupNameTextBox" MaxLength="50" runat="server" Text='<%# Bind("GroupName") %>' /><br />
Id:
<asp:TextBox ID="IdTextBox" runat="server" Text='<%# Bind("Id") %>'></asp:TextBox><br />
GroupDescr:
<asp:TextBox ID="GroupDescrTextBox" MaxLength="255" runat="server" Text='<%# Bind("GroupDescr") %>' /><br />
ExcludeFromUserFilter:
<asp:CheckBox ID="chbExcludefromDocFilter" runat="server" Checked='<%# Bind("ExcludeFromUserFilter") %>' /><br />
Members:
<asp:TextBox ID="MembersTextBox" runat="server" Text='<%# Bind("Members") %>' /><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Gid:
<asp:Label ID="GidLabel" runat="server" Text='<%# Bind("Gid") %>' /><br />
GroupName:
<asp:Label ID="GroupNameLabel" runat="server" Text='<%# Bind("GroupName") %>' /><br />
Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Bind("Id") %>' /><br />
GroupDescr:
<asp:Label ID="GroupDescrLabel" runat="server" Text='<%# Bind("GroupDescr") %>' /><br />
<%--ExcludeFromUserFilter: <asp:Label ID="lblExcludefromDocFilter" runat="server" Text='<%# Bind("ExcludeFromUserFilter") %>' /><br />--%>
Members:
<asp:Label ID="MembersLabel" runat="server" Text='<%# Bind("Members") %>' /><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit" />
</ItemTemplate>
</asp:FormView>
<asp:Label ID="lblMsg" runat="server" ForeColor="Red" />
<asp:ObjectDataSource ID="PermGroupObjectDataSource1" runat="server" DataObjectTypeName="Accenture.CSTPrague.eAPI.PermGroup"
SelectMethod="FetchPermGroupFromDB" TypeName="Accenture.CSTPrague.eAPI.WebDB_Perm"
UpdateMethod="StorePermGroupToDB" OnUpdating="PermGroupObjectDataSource1_Updating">
<SelectParameters>
<asp:SessionParameter Name="o" SessionField="oPermGroup" Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
</form>
Set ValidationGroup="xxx" in your validate control and submit button.(don't cancel button")
Try
<asp:RequiredFieldValidator ID="rqrgFldVldtr_GroupName"
ControlToValidate="GroupNameTextBox" **ValidationGroup="xxx"** Display="Dynamic" ErrorMessage="<"
meta:resourcekey="RequiredFieldValidator1Resource2"
runat="server">
</asp:RequiredFieldValidator>
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" **ValidationGroup="xxx"** Text="Save"
Width="67px" CssClass="ButtonS1"/>
<asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click"
Text="Cancel" CssClass="ButtonS1" CausesValidation="false"/>