I wish to set the datasource as my bound field item, but i failed to do so, my output is not as my expected
output
boundfield userName movieComment
expected output
boundfield
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmdReadComment = new SqlCommand("SELECT [userName],[movieComment] FROM [movieCommentTable] WHERE [movieTitle]='" + lblHeadTitle.Text + "'", conn);
SqlDataReader dtrReadComment;
conn.Open();
dtrReadComment = cmdReadComment.ExecuteReader();
GridView2.DataSource = dtrReadComment;
GridView2.RowStyle.Height = 200;
BoundField userNameBF = new BoundField();
userNameBF.DataField = "userName";
userNameBF.ItemStyle.Width = 180;
GridView2.Columns.Add(userNameBF);
GridView2.DataBind();
Try this
GridView2.AutoGenerateColumns = false;. Read more on MSDN.This way you tell
GridViewnot to generate columns on its own.Another solution can be, change your query to
And comment out your custom code for
BoundField.Hope this works for you