hi,
i m creating a grid view control in web part.. for that i wrote the following code, but grid does't appears.. plz help me out...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Drawing;
using System.Data.SqlClient;
using System.Data;
namespace _Test_
{
/// <summary>
/// Description for List.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:List runat=server></{0}:List>"),
XmlRoot(Namespace = "_Test_")]
public class List : Microsoft.SharePoint.WebPartPages.WebPart
{
GridView Gridview = new GridView();
// [Browsable(true),
// Category("Miscellaneous"),
// DefaultValue(defaultText),
// WebPartStorage(Storage.Personal),
// FriendlyName("Text"),
// Description("Text Property")]
//public string Text
//{
// get
// {
// return text;
// }
// set
// {
// text = value;
// }
//}
///// <summary>
///// Constructor for the class.
///// </summary>
//public List()
//{
//}
protected override void CreateChildControls()
{
this.Controls.Clear();
//gridview properties
//GridView Gridview = new GridView();
Gridview.ID = "grid";
Controls.Add(Gridview);
Gridview.BorderColor = ColorTranslator.FromHtml("#000080");
Gridview.AutoGenerateEditButton = true;
Gridview.AutoGenerateEditButton = true;
BoundField gridColumn = new BoundField();
gridColumn.DataField = "Name";
gridColumn.HeaderText = "Name";
Gridview.Columns.Add(gridColumn);
gridColumn = new BoundField();
gridColumn.DataField = "List";
gridColumn.HeaderText = "Todolist";
Gridview.Columns.Add(gridColumn);
this.Controls.Add(Gridview);
DataSet ds = new DataSet();
string select = "select *from Todolist";
SqlConnection conn = new SqlConnection("server=IE10DT2K3955ZL1;Initial Catalog=anupam;Integrated Security=True;");
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(select, conn);
da.Fill(ds, "Todolist");
Gridview.DataSource = ds;
Gridview.DataBind();
conn.Close();
//base.OnPreRender(e);
}
catch
{
Label lb1 = new Label();
lb1.Text = "Data can't displayed";
Console.WriteLine("" + lb1);
}
// panel properties
Panel mainPanel = new Panel();
mainPanel.ID = "panel";
Controls.Add(mainPanel);
mainPanel.BackColor = Color.AliceBlue;
mainPanel.Height = 100;
mainPanel.Controls.Add(Gridview);
//base.CreateChildControls();
}
}
}
i m using sql server and the database is on server side and using windows authentication mode.. i m able to only blank panel with aliceblue color background...
telll me where i need to change or what's wrong here..