TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kamala Veni
NA
65
21.5k
Convert GridView Columns to Rows frm the sql tble saved data
Apr 19 2016 6:37 AM
hi
I have saved data's in Sql table,i want to display that columns as rows,how to display? and also need a edit and save button in the that Gridview. plz help..
ex:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CellPadding="4"
ForeColor="#333333" ShowFooter="True"
Width="16px" Height="10px" style="background:#F7C7A9; margin-left: 13px; margin-bottom: 0px;">
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
protected void BindGridView()
{
// string con = ConfigurationManager.ConnectionStrings["cppschConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["App"].ToString());
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select blk_1,blk_2,blk_3,blk_4,blk_5,blk_6,blk_7,blk_8,blk_9,blk_10,blk_11,blk_12,blk_13,blk_14,blk_15,blk_16,blk_17,blk_18,blk_19,blk_20,blk_21,blk_22,blk_23,blk_24,blk_25,blk_26,blk_27,blk_28,blk_29,blk_30,blk_31,blk_32,blk_33,blk_34,blk_35,blk_36,blk_37,blk_38,blk_39,blk_40,blk_41,blk_42,blk_43,blk_44,blk_45,blk_46,blk_47,blk_48,blk_49,blk_50,blk_51,blk_52,blk_53,blk_54,blk_55,blk_56,blk_57,blk_58,blk_59,blk_60,blk_61,blk_62,blk_63,blk_64,blk_65,blk_66,blk_67,blk_68,blk_69,blk_70,blk_71,blk_72,blk_73,blk_74,blk_75,blk_76,blk_77,blk_78,blk_79,blk_80,blk_81,blk_82,blk_83,blk_84,blk_85,blk_86,blk_87,blk_88,blk_89,blk_90,blk_91,blk_92,blk_93,blk_94,blk_95,blk_96 from tbl_sch1", con);
// SqlDataAdapter da = new SqlDataAdapter("select * from tbl_sch1",con);
// SqlDataAdapter da = new SqlDataAdapter("select Blk_1,Blk_2,Blk_3,Blk_4,Blk_5,Blk_6,Blk_7,Blk_8,Blk_9,Blk_10,Blk_11,Blk_12,Blk_13,Blk_14,Blk_15,Blk_16,Blk_17,Blk_18,Blk_19,Blk_20 from tbl_sch1 ", con);
con.Open();
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
public DataSet FlipDataSet(DataSet my_DataSet)
{
DataSet ds = new DataSet();
foreach (DataTable dt in my_DataSet.Tables)
{
DataTable table = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
table.Columns.Add(Convert.ToString(i));
}
DataRow r = null;
for (int k = 0; k < dt.Columns.Count; k++)
{
r = table.NewRow();
r[0] = dt.Columns[k].ToString();
for (int j = 1; j <= dt.Rows.Count; j++)
r[j] = dt.Rows[j - 1][k];
table.Rows.Add(r);
}
ds.Tables.Add(table);
}
return ds;
}
protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-color: #c3cecc";
}
}
Reply
Answers (
4
)
not delete record in gridview
AnjularJS