Click here to Skip to main content
15,867,308 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: IIS changing the IE11 document mode from 11 (Default) to 7 (Default) when browsing to a site Pin
Stephen Holdorf31-Jan-20 7:50
Stephen Holdorf31-Jan-20 7:50 
QuestionSQL and IIS error when publish an ASP .NET application to IIS Pin
Stephen Holdorf30-Jan-20 12:54
Stephen Holdorf30-Jan-20 12:54 
AnswerRe: SQL and IIS error when publish an ASP .NET application to IIS Pin
phil.o30-Jan-20 13:07
professionalphil.o30-Jan-20 13:07 
QuestionHow do I solve error StatusCode: 500? Pin
Member 1140330430-Jan-20 4:01
Member 1140330430-Jan-20 4:01 
AnswerRe: How do I solve error StatusCode: 500? Pin
Richard Deeming30-Jan-20 4:10
mveRichard Deeming30-Jan-20 4:10 
GeneralRe: How do I solve error StatusCode: 500? Pin
Member 1140330430-Jan-20 4:44
Member 1140330430-Jan-20 4:44 
QuestionHTTP Error 500.19 - Internal Server Error - The requested page cannot be accessed because the related configuration data for the page is invalid Pin
simpledeveloper29-Jan-20 12:09
simpledeveloper29-Jan-20 12:09 
AnswerRe: HTTP Error 500.19 - Internal Server Error - The requested page cannot be accessed because the related configuration data for the page is invalid Pin
Richard Deeming30-Jan-20 1:06
mveRichard Deeming30-Jan-20 1:06 
GeneralRe: HTTP Error 500.19 - Internal Server Error - The requested page cannot be accessed because the related configuration data for the page is invalid Pin
simpledeveloper30-Jan-20 14:28
simpledeveloper30-Jan-20 14:28 
Question(SOLVED) Any ideas why gridview is not getting populated with data from the database? Pin
samflex29-Jan-20 9:30
samflex29-Jan-20 9:30 
Hello experts,

We have an app that prompts employees to enter his/her empID.

Once the employee enters his/her ID, the VB/Stored Proc checks the ID to determine if user has entered his/her information from previous year.

If no, the user gets a blank page to enter his/her data.

If user had entered data the previous year, our objective is to have data populate the GridView control giving the user the opportunity to review data and make changes if necessary.

The code largely works when populating data outside of GridView.

However, GridView is not getting populated with the two sourcename and spousename.

Obviously, it is not recognizing textboxes from GridView.

Any ideas how to resolve this?

My abbreviated code below. Thanks a lot in advnce

Sorry for the long code.

Stored Proc
ALTER PROCEDURE [dbo].[ValidateEmpID]
@empID varchar(50)
AS
BEGIN
SET NOCOUNT OFF;
SELECT employeeName, email, emptitle, EmpID,
    CASE WHEN YEAR(d.dateCreated) = YEAR(getdate()) -1 THEN 1 ELSE 0 END as previousYear, 
    CASE WHEN YEAR(d.dateCreated) = YEAR(getdate()) THEN 1 ELSE 0 END as thisYear 
    FROM Employees e 
    INNER JOIN dateDetails d on e.employeeID = d.EmployeeID 
    INNER JOIN SourceDetails so on e.employeeID = so.EmployeeID
	INNER JOIN SpouseDetails sp on e.employeeID = sp.employeeID 
    WHERE EmpID=@empID
 END

//HTML

  <div class="table-responsive">
    <table class="table">
    <tr>
	<td>
	<div class="form-group">
	<label for="lblEname"><span style="font-weight:bold;font-size:16px;color:#000000;">Employee Name</span><span style="color:#ff0000">*</span></label>
	 <asp:TextBox ID="txteName" placeholder="Employee name..." style="width:200px;" class="form-control" runat="server"></asp:TextBox>
	<asp:RequiredFieldValidator id="RequiredFieldValidator2" Font-Bold="true" 
	 SetFocusOnError="true" runat="server" 
	 ErrorMessage="*" ControlToValidate="txteName" /><br />
	 </div>
	 </td>
	<td>
	 <div class="form-group">
	<label id="lblTitle"><span style="font-weight:bold;font-size:16px;color:#000000;">Your title</span><span style="color:#ff0000">*</span></label>
	<asp:TextBox ID="txttitle" placeholder="Employee title..." style="width:200px;" class="form-control" runat="server"></asp:TextBox>
       <asp:RequiredFieldValidator id="RequiredFieldValidator3" Font-Bold="true" 
	   SetFocusOnError="true" runat="server" 
	 ErrorMessage="*" ControlToValidate="txttitle" />
       </div> 
       </td>
	<td>
	 <div class="form-group">
	 <label id="lblEmail"><span style="font-weight:bold;font-size:16px;color:#000000;">Your email address</span><span style="color:#ff0000">*</span></label>
	<asp:TextBox ID="txtemail" placeholder="Employee email..." style="width:200px;" class="form-control" runat="server"></asp:TextBox>
       <asp:RequiredFieldValidator id="RequiredFieldValidator4" Font-Bold="true" 
	SetFocusOnError="true" runat="server" 
	ErrorMessage="*" ControlToValidate="txtemail" />
	</div>
	</td>
    </tr>
   </table>
</div>



<table class="table">
<tr>
<td>
  <asp:gridview ID="Gridview1" RowStyle-Wrap="false" gridlines="None" CssClass="responsiveTable1" runat="server" ShowFooter="true" AutoGenerateColumns="false" onrowdatabound="Gridview1_RowDataBound" OnRowDeleting="Gridview1_RowDeleting">
    <Columns>
    <asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
    <asp:TemplateField HeaderText="Name">
     <headerstyle horizontalalign="Left" />
	<ItemTemplate>
	    <asp:TextBox ID="txtsourcename" Text='<%# Eval("sourcename") %>' placeholder="Name...(e.g, Jane Doe)" runat="server" style="width:375px;" AutoPostBack="true" class="form-control textClass" OnTextChanged="txtsourcename_TextChanged"></asp:TextBox><br />
	    <asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><span style="color:#ff0000">*Check this box if N/A</span>
	</ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Address">
    <ItemStyle HorizontalAlign="Left"></ItemStyle>
	<ItemTemplate>
	    <asp:TextBox ID="txtsourceaddress" Text='<%# Eval("sourceaddress") %>' placeholder="Address..." runat="server" style="width:375px;" class="form-control textClass"></asp:TextBox><br /><br />
	</ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="">
	<ItemTemplate>
	 <asp:Button ID="ButtonAdd" runat="server" Text="Add another row if needed" 
		onclick="ButtonAdd_Click" CssClass="grvAddButton" /><br /><br /><br>
	</ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="">
	<ItemTemplate>
	 <asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
		 CssClass="grvDelButton" OnClientClick="return confirm('Are you sure you want to remove this row?')"  /> <br /><br /><br />
	</ItemTemplate>
    </asp:TemplateField> 
    </Columns>
  </asp:gridview>
</td>
</tr>
</table>
   
//VB
Protected Sub txtEmpID_TextChanged(sender As Object, e As EventArgs) Handles txtEmpID.TextChanged
  If Not String.IsNullOrEmpty(txtEmpID.Text) Then
      Dim Conn As SqlConnection
      'Read in connection String
      Conn = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
      Conn.Open()
      Dim cmd As New SqlCommand("ValidateEmpID", Conn)
      cmd.CommandType = CommandType.StoredProcedure
      cmd.Parameters.AddWithValue("@empID", txtEmpID.Text)
      Dim dr As SqlDataReader = cmd.ExecuteReader()
      If dr.HasRows Then
	  'Employee exists'
	  dr.Read()
	  checkusername.Visible = True
	  dprocessed.Visible = True
	  If dr("previousYear").ToString() = "1" Then
	      imgstatus.ImageUrl = "images/NotAvailable.jpg"
	      lblStatus.Text = "Please verify your information for accuracy. Then complete rest of the form."
	      lblStatus.ForeColor = System.Drawing.Color.Red
	      System.Threading.Thread.Sleep(300)
	      txteName.Text = dr("employeeName").ToString()
	      txttitle.Text = dr("empTitle").ToString()
	      txtemail.Text = dr("email").ToString()
	      txtEmpID.Text = dr("empID").ToString()

	      Dim currentRow As GridViewRow = CType((CType(sender, TextBox)).Parent.Parent.Parent.Parent, GridViewRow)
	      Dim txtsource As TextBox = CType(currentRow.FindControl("txtsourcename"), TextBox)
	      txtsource.Text = dr("sourcename").ToString()
	      Dim txtsource As TextBox = CType(currentRow.FindControl("txtspousename"), TextBox)
	      txtspouse.Text = dr("spousename").ToString()                      

	  ElseIf dr("thisYear").ToString() = "1" Then
	      imgstatus.ImageUrl = "images/NotAvailable.jpg"
	      lblStatus.Text = "You have already completed this Disclosure form. Please close the form. If you feel there is a mistake, please contact Clerk at xxx-xxx-xxxx"
	      lblStatus.ForeColor = System.Drawing.Color.Red
	      System.Threading.Thread.Sleep(300)
	      txteName.Text = dr("employeeName").ToString()
	      txttitle.Text = dr("empTitle").ToString()
	      txtemail.Text = dr("email").ToString()
	      txtEmpID.Text = dr("empID").ToString()
	      txteName.Enabled = False
	      txttitle.Enabled = False
	      txtemail.Enabled = False
	      txtEmpID.Enabled = False
	      GridPanels.Enabled = False
	      dprocessed.Visible = True
	      btnNext.Enabled = False
	  Else
	      'not this year, nor the previous year'
	  End If
      Else
	  checkusername.Visible = True
	  dprocessed.Visible = True
	  imgstatus.ImageUrl = "images/Icon_Available.gif"
	  lblStatus.Text = "Proceed to complete entire form"
	  lblStatus.ForeColor = System.Drawing.Color.Red
	  System.Threading.Thread.Sleep(300)
	  txteName.Text = ""
	  txttitle.Text = ""
	  txtemail.Text = ""
      End If
  Else
      checkusername.Visible = False
  End If
End Sub


modified 30-Jan-20 14:12pm.

SuggestionRe: Any ideas why gridview is not getting populated with data from the database? Pin
Richard Deeming30-Jan-20 1:02
mveRichard Deeming30-Jan-20 1:02 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
samflex30-Jan-20 3:58
samflex30-Jan-20 3:58 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
Richard Deeming30-Jan-20 4:05
mveRichard Deeming30-Jan-20 4:05 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
samflex30-Jan-20 4:20
samflex30-Jan-20 4:20 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
Richard Deeming30-Jan-20 4:53
mveRichard Deeming30-Jan-20 4:53 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
samflex30-Jan-20 5:14
samflex30-Jan-20 5:14 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
samflex30-Jan-20 5:41
samflex30-Jan-20 5:41 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
Richard Deeming30-Jan-20 5:47
mveRichard Deeming30-Jan-20 5:47 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
samflex30-Jan-20 6:45
samflex30-Jan-20 6:45 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
Richard Deeming30-Jan-20 7:08
mveRichard Deeming30-Jan-20 7:08 
GeneralRe: Any ideas why gridview is not getting populated with data from the database? Pin
samflex30-Jan-20 8:11
samflex30-Jan-20 8:11 
QuestionWriting a client app for OData Pin
simpledeveloper29-Jan-20 7:13
simpledeveloper29-Jan-20 7:13 
QuestionDropdown Filtering in grideview vb.net Pin
Member 315525329-Jan-20 4:16
Member 315525329-Jan-20 4:16 
QuestionFiles download fails for ipad and iphone clients Pin
alesanndro28-Jan-20 20:34
alesanndro28-Jan-20 20:34 
AnswerRe: Files download fails for ipad and iphone clients Pin
Nathan Minier29-Jan-20 5:42
professionalNathan Minier29-Jan-20 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.