Hi all below are my codes for my GridView control. I have 2 columns Name and patientName appearing. I am not sure where the column patientName is appearing from. I have attached an image as well of what I face.
All I would need is under the Name column for the name to appear. Thanks.
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("select patientName from xxx where patientNRIC='" + searchPatNric + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
Thiv
Member
5 Points
45 Posts
Extra column appearing in GridView
Jan 05, 2013 12:51 PM|LINK
Hi all below are my codes for my GridView control. I have 2 columns Name and patientName appearing. I am not sure where the column patientName is appearing from. I have attached an image as well of what I face.
All I would need is under the Name column for the name to appear. Thanks.
<asp:GridView ID="GridView1" runat="server" Width = "550px"
Font-Names = "Arial" AutoGenerateColumns="true"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "LightSteelBlue"
HeaderStyle-BackColor ="Blue" AllowPaging ="false" ShowFooter = "false">
<Columns>
<asp:TemplateField HeaderText="Name" HeaderStyle-HorizontalAlign="Left"
ControlStyle-Width="50px">
<EditItemTemplate>
<asp:TextBox ID="txtPatName" runat="server" Text='<%#Bind("patientName") %>' Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<%# Eval("patientName")%>
</ItemTemplate>
</asp:TemplateField></Columns></asp:GridView>
private void BindData(String searchPatNric)
{
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("select patientName from xxx where patientNRIC='" + searchPatNric + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
oned_gk
All-Star
31361 Points
6411 Posts
Re: Extra column appearing in GridView
Jan 05, 2013 12:55 PM|LINK
Thiv
Member
5 Points
45 Posts
Re: Extra column appearing in GridView
Jan 05, 2013 12:59 PM|LINK
Oh yes. Thanks a lot! :)