ASPX Code:
<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="#EDEDED" HeaderStyle-ForeColor="#184F46" HeaderStyle-Height="40px" HeaderStyle-HorizontalAlign="Center" OnRowDataBound="Gridview1_RowDataBound" SelectedRowStyle-BackColor="#F9CACA" ShowFooter="True" TabIndex="9" Width="100%">
<asp:TemplateField HeaderStyle-Height="30px" HeaderText="Package Type">
<ItemTemplate>
<asp:DropDownList ID="ddlPackageType" runat="server" Width="70px">
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle Height="30px" Width="8%" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</GridView>
CODE Behind Code for Binding Data :
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataSet dsPackageType = new DataSet();
//Write Code For Getting data from Database and add it in dsPackageType Dataset .
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control ctrl = e.Row.FindControl("ddlPackageType");
if (ctrl != null)
{
DropDownList dd = ctrl as DropDownList;
dd.DataTextField = "PackageType";
dd.DataValueField= "Id";
dd.DataSource = dsPackageType;
dd.DataBind();
dd.Items.Insert(0, new ListItem("- Select -", "0"));
}
}
}
No comments:
Post a Comment