Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
4
Answers
Gridview and Detail view
Murugavel Sadagopan
14y
8.3k
1
Reply
Hi,
I have two table
Table 1: job_details
Job_id
Project Name
Table 2: chap_details
chap_id
Job_id
chap_no
ms_pages
In the aspx page, I have grid view and details view.
My problem is
In the gridview, template fields called job_id, chapter_no
and view button
whenever i select the chapter of particular job and click the view button.
It displays the ms pages of the particular job and chapter.
Note: A job can have multiple chapters
But in the following program works when i select the first value value in the dropdown chapter list box.
Plz help me.
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 605px">
<asp:GridView ID="grvTask" CssClass="gvHeader" runat="server" AutoGenerateColumns="False"
RowStyle-HorizontalAlign="Center"
GridLines="None" PagerStyle-Width="5%" HeaderStyle-BackColor="#72a1c1" HeaderStyle-ForeColor="white"
PagerStyle-Font-Bold="true" PagerStyle-HorizontalAlign="Center" PagerStyle-BackColor="linen" PageSize="5" OnSelectedIndexChanged="grvTask_SelectedIndexChanged" CellPadding="4" ForeColor="#333333" >
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="2%" HorizontalAlign="Center"/>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Job ID">
<ItemTemplate>
<asp:Label ID="lblJob_no" runat="server" Text='<%#Eval("Job_id") %>' />
<asp:HiddenField ID="hdnJobNo" runat="server" Value='<%#Eval("Job_id") %>' />
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Chapters">
<ItemTemplate>
<asp:DropDownList ID="ddChapter" runat="server" AutoPostBack="false" Width="120px" ></asp:DropDownList>
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="5%"/>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnView" runat="server" Text="View" OnClick="btnView_Click" />
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="15%" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" Width="5%" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</td>
</tr>
</table>
</div>
<div id="secondDiv" runat="server">
<table>
<tr>
<td style="width: 283px">
<asp:GridView ID="grvDetails" CssClass="gvHeader" runat="server" AutoGenerateColumns="false"
RowStyle-HorizontalAlign="Center"
GridLines="Horizontal" PagerStyle-Width="5%" HeaderStyle-BackColor="#72a1c1" HeaderStyle-ForeColor="white"
PagerStyle-Font-Bold="true" PagerStyle-HorizontalAlign="Center" PagerStyle-BackColor="linen"
AllowPaging="false" PageSize="5" Width="611px">
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="2%" HorizontalAlign="Center"/>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Job ID">
<ItemTemplate>
<asp:Label ID="lblJob_no" runat="server" Text='<%#Eval("Job_id") %>' />
<asp:HiddenField ID="hdnJobNo" runat="server" Value='<%#Eval("Job_id") %>' />
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Chapters">
<ItemTemplate>
<asp:Label ID="lblChapter" runat="server" Text='<%#Eval("chapter_no") %>' />
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="MS Pages">
<ItemTemplate>
<asp:Label ID="lblReworkCount" runat="server" Text='<%#Eval("ms_pages") %>' />
<%--<asp:Button ID="btnView" runat="server" Text="View" OnClick="btnView_Click" />--%>
</ItemTemplate>
<HeaderStyle CssClass="columnHeading" Width="15%" />
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Center" />
<PagerStyle BackColor="Linen" Font-Bold="True" HorizontalAlign="Center" Width="5%" />
<HeaderStyle BackColor="#72A1C1" ForeColor="White" />
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
C#:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
public partial class Default2 : System.Web.UI.Page
{
SqlConnection sqlCon = new SqlConnection();
SqlCommand sqlCmd = new SqlCommand();
string connectionString;
protected void Page_Load(object sender, EventArgs e)
{
OpenConnection();
if (!IsPostBack)
{
fnFillGrid();
fillDdlChapter();
secondDiv.Visible = false;
}
}
public void OpenConnection()
{
connectionString = System.Configuration.ConfigurationSettings.AppSettings["myconn"];
sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
}
public void fnFillGrid()
{
DataSet ds = new DataSet();
sqlCmd = new SqlCommand("select distinct(job_id) from job_details order by job_id", sqlCon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlCmd;
da.Fill(ds);
grvTask.DataSource = ds;
grvTask.DataBind();
}
public void fillDdlChapter()
{
for (int i = 0; i < grvTask.Rows.Count; i++)
{
Label lblJob_no = ((Label)(grvTask.Rows[i].Cells[2].Controls[1]).FindControl("lblJob_no"));
DropDownList ddlchapter = ((DropDownList)(grvTask.Rows[i].Cells[2].Controls[1]).FindControl("ddChapter"));
DataSet ds = new DataSet();
sqlCmd = new SqlCommand("select distinct(chapter_no),job_id from chap_details where job_id ='" + lblJob_no.Text + "' ", sqlCon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlCmd;
da.Fill(ds);
ddlchapter.DataSource = ds;
ddlchapter.DataValueField = "job_id";
ddlchapter.DataTextField = "chapter_no";
ddlchapter.DataBind();
}
}
protected void btnView_Click(object sender, EventArgs e)
{
string jobno = Convert.ToString(((HiddenField)(((Button)sender).Parent.FindControl("hdnJobNo"))).Value);
string chapter = Convert.ToString(((DropDownList)(((Button)sender).Parent.FindControl("ddChapter"))).SelectedItem);
secondDiv.Visible = true;
DataSet ds = new DataSet();
sqlCmd = new SqlCommand("select job_id,chapter_no,ms_pages from chap_details where job_id='" + jobno + "' and chapter_no='" + chapter + "'", sqlCon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlCmd;
da.Fill(ds);
grvDetails.DataSource = ds;
grvDetails.DataBind();
}
}
Problem is: when i am selecting the second item in the dropdown box of a particular job means it shoes the first item value in the details view.
bye
Murugavel S
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
Textbox value gone when postback occurs
crystal reports