मैं एक नेस्टेड ग्रिडव्यू बनाने के लिए एक से अधिक दिनों से खोज कर रहा हूं जिसे सी # विंडोज़ फॉर्म में जोड़ा जा सकता है। मुझे कई उदाहरण मिल गए हैं जो एएसपी.नेट का उपयोग कर रहे हैं, हालांकि मुझे सी # के साथ कोई भी नहीं मिला। मैं एक मास्टर/विस्तार GridView कि नीचे दिए गए लिंक में से एक की तरह लग रहा चाहते हैं: http://ilovedeveloper.blogspot.com/2009/05/nested-gridview-using-c.htmlएक नेस्टेड ग्रिडव्यू उदाहरण
उत्तर
आप नेस्टेड gridview बनाने के लिए टेम्पलेट कॉलम का उपयोग कर सकते हैं, तो आप स्तंभ की पहली पंक्ति में टेम्पलेट कॉलम के अंदर HTML तालिका का निर्माण करने की जरूरत है पंक्ति डेटाबेस डेटाबेस का उपयोग कर कस्टम बाध्यकारी का उपयोग कर मुख्य ग्रिड पंक्तियों से भरें। आप धीमे दौड़ो नीचे दिए गए लिंक के साथ HTML तालिका
जांच की दूसरी पंक्ति के अंदर घोंसला ग्रिड दृश्य जोड़ने .. http://www.dotnetfox.com/articles/multilevel-nested-gridview-in-Asp-Net-using-C-Sharp-1012.aspx
आप कई संसाधन हैं जो इस प्रदान करता है:
Walkthrough: Creating a Nested GridView Control
Nested GridView Example in ASP.Net using C# and VB.Net
मैं वास्तव में क्या कर रहा हूं एक मास्टर/विवरण ग्रिड व्यू को पूरी तरह से सी # में बनाना है। मैं इस नियंत्रण का उपयोग विंडोज़ फॉर्म में करना चाहता हूं। – mrida
छवि
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
<!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></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.Grid td
{
background-color: #A1DCF2;
color: black;
font-size: 10pt;
line-height:200%
}
.Grid th
{
background-color: #3AC0F2;
color: White;
font-size: 10pt;
line-height:200%
}
.ChildGrid td
{
background-color: #eee !important;
color: black;
font-size: 10pt;
line-height:200%
}
.ChildGrid th
{
background-color: #6C6C6C !important;
color: White;
font-size: 10pt;
line-height:200%
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[src*=plus]").live("click", function() {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "images/minus.png");
});
$("[src*=minus]").live("click", function() {
$(this).attr("src", "images/plus.png");
$(this).closest("tr").next().remove();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
DataKeyNames="CustomerID" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="OrderId" HeaderText="Order Id" />
<asp:BoundField ItemStyle-Width="150px" DataField="OrderDate" HeaderText="Date" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="ContactName" HeaderText="Contact Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="City" HeaderText="City" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
सी #
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class CS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvCustomers.DataSource = GetData("select top 10 * from Customers");
gvCustomers.DataBind();
}
}
private static DataTable GetData(string query)
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = query;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string customerId = gvCustomers.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
gvOrders.DataSource = GetData(string.Format("select top 3 * from Orders where CustomerId='{0}'", customerId));
gvOrders.DataBind();
}
}
}
क्यों डाउनवोट्स .. – Sasidharan
मेरे लिए काम किया, तो आपको मेरा अपवित्र मिल गया है। – BryPie
एलओएल सासिधरन! मुझे लगता है कि आप डाउनवॉट्स प्राप्त कर रहे हैं क्योंकि आप ओपी के सवाल को बहुत सावधानी से नहीं पढ़ते हैं। ओपी ने स्पष्ट रूप से उल्लेख किया है कि ओपी विशेष रूप से विंडोजफॉर्म ग्रिड की तलाश में है और एएसपी.Net नहीं! उम्मीद है कि यह आपके प्रश्न का उत्तर देगा। – Vincy
SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
// This method is used to bind gridview from database
protected void BindGridview()
{
con.Open();
SqlCommand cmd = new SqlCommand("select TOP 4 CountryId,CountryName from Country", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
gvParentGrid.DataSource = ds;
gvParentGrid.DataBind();
}
protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
GridView gv = (GridView)e.Row.FindControl("gvChildGrid");
int CountryId = Convert.ToInt32(e.Row.Cells[1].Text);
SqlCommand cmd = new SqlCommand("select * from State where CountryID=" + CountryId, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
gv.DataSource = ds;
gv.DataBind();
}
}
कृपया कोड-केवल उत्तर पोस्ट न करें। कृपया अपने उत्तर में कुछ स्पष्टीकरण जोड़ें। किसी भी स्पष्टीकरण के बिना यह अस्पष्ट है कि आपकी पोस्ट का जवाब होना चाहिए या नहीं। – honk
- 1. एक ग्रिडव्यू
- 2. एक खाली ग्रिडव्यू
- 3. एक सूचीदृश्य से ग्रिडव्यू
- 4. ग्रिडव्यू
- 5. ग्रिडव्यू
- 6. ग्रिडव्यू
- 7. ग्रिडव्यू
- 8. ग्रिडव्यू
- 9. ग्रिडव्यू
- 10. ग्रिडव्यू
- 11. ग्रिडव्यू
- 12. ग्रिडव्यू
- 13. ग्रिडव्यू
- 14. ग्रिडव्यू
- 15. ग्रिडव्यू
- 16. ग्रिडव्यू
- 17. ग्रिडव्यू
- 18. ग्रिडव्यू
- 19. Asp.Net ग्रिडव्यू
- 20. ग्रिडव्यू सेल
- 21. Asp.net ग्रिडव्यू
- 22. नेस्टेड फ़ंक्शंस के वास्तविक विश्व उदाहरण
- 23. ओकैमल में नेस्टेड हस्ताक्षर का उदाहरण?
- 24. एएसपी.NET ग्रिडव्यू
- 25. ग्रिडव्यू setOnItemClickListener
- 26. ग्रिडव्यू नियंत्रण
- 27. एंड्रॉइड: ग्रिडव्यू
- 28. ग्रिडव्यू एंड्रॉइड
- 29. ग्रिडव्यू - व्यूपर
- 30. एएसपी.नेट: ग्रिडव्यू
[ExtGridView] (http://www.codeproject.com/Articles/12299/ExtGridView) रुचि का हो सकता है, मैंने इसका उपयोग नहीं किया है, लेकिन मेरा मानना है कि यह सी # में है। –
मैं वास्तव में क्या कर रहा हूं वह मास्टर/विवरण ग्रिड व्यू को पूरी तरह से सी # में बनाना है। मैं इस नियंत्रण का उपयोग विंडोज़ फॉर्म में करना चाहता हूं। – mrida