i have developed a gridview in which i have a dropdownlist which must be loaded dynamically in the pageload event.I dont know how to mention the dropdownlist present within the gridview.
I tried as follows,
protected void LoadShipping()
{
int index;
index = 0;
con.Open();
cmd = new SqlCommand("SC_SP_SelectShippingRates", con);
cmd.CommandType = CommandType.StoredProcedure;
dr = cmd.ExecuteReader();
while (dr.Read())
{
ddlshipping.Items.Add(dr["Shipping"].ToString());
ddlshipping.Items[index].Value = dr["ShippingID"].ToString();
index++;
}
con.Close();
}
but this causes an error that the ddlshipping doesnot exists in the current context.
Design is as follows:
<asp:GridView ID="gvcheckout" runat="server" AutoGenerateColumns="False" OnRowCommand="gvcheckout_RowCommand" OnRowUpdating="gvcheckout_RowUpdating" OnSelectedIndexChanging="gvcheckout_OnSelectedIndexChanging" OnRowDataBound="gvcheckout_RowDataBound"
CellPadding="3" CssClass="GridViewStyle" Width="100%" Height="350px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblShipping" runat="server" Text="Shipping" Width="100px" ></asp:Label>
<asp:DropDownList ID="ddlshipping" runat="server" AutoPostBack="true" Width="200px"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="rowdata" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="gridheading" BackColor="#004d6a" ForeColor="white" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="rowdata1" BackColor="#F5F5F5" />
</asp:GridView>
how can i load dynaic values in the dropdownlist present in the grid ?
How can i change the properties of the controls present in the grid in user defined function ?