DataTable dt; string str = ConfigurationManager.ConnectionStrings["conn"].ToString(); protected void Page_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(str); conn.Open(); dt = new DataTable(); DataColumn dc = new DataColumn(); dc = new DataColumn("Medicine"); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr["Medicine"] = this.medicine.SelectedValue; dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); }
<asp:DropDownList ID="medicine" runat="server" AutoPostBack="True" Height="22px" Width="262px"> <asp:ListItem>agfdgd</asp:ListItem> <asp:ListItem>bgfdgd</asp:ListItem> <asp:ListItem>cgfdgd</asp:ListItem> <asp:ListItem>dgfdgd</asp:ListItem> <asp:ListItem>egfdgd</asp:ListItem> <asp:ListItem>fgfdgd</asp:ListItem> <asp:ListItem>ggfdgd</asp:ListItem> </asp:DropDownList> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="59px" Width="404px"> <Columns> <asp:BoundField DataField="Medicine" HeaderText="name" /> </Columns> </asp:GridView>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)