Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi group,

 

I am using a Datagrid with Dropdown, and the values which I have to show in drop are derived from output of a query so I cant use DataSource directly to populate the Dropdown and cant even hardcoad the Listitems in dropdown.

These populated entries are also supposed to be used in an Insert Query.

 

This is how I have added the dropdown in Datagrid,

 

<asp:TemplateColumn HeaderText="MTD">

<ItemTemplate> <asp:DropDownList id="list" AutoPostBack="True" runat="server"

Width="150px">' DataTextField="X_VALUE">

</asp:DropDownList>

</ItemTemplate>

</asp:TemplateColumn>

 

 

Please suggest me how to do this dynamically or is there any other way to do this?

(I am using ASP.NET 1.1)

 

Thanks and Regards,

Anup

Posted

In each item is the DropDownList going to contain the same values for each row of the DataGrid or are you running a seperate query for each row in the DataGrid.

 

If the second is true are you aware of the performance implications? If performance isn't a requirement I can help you from there, but I don't think this is the route your taking.

 

If the first is true then you CAN use a DataSource. If the Query returns a cursor (a SELECT statement) then just populate a DataSet/DataTable and use that as your DataSource.

 

I would need more specific information to help you further.

Posted

I have a datagrid with dropdown in my application.

I want to fill the data in dropdown by an ArrayList

for that I am using "e.Item.FindControl("DropdownId")"

but this function is returning NULL THUS I m getting exception

"Object Refrence not set to an Instance to Object",

 

Here is the code I wrote (ASP.NET 1.1)...

 

Hope I get some help from you,

 

 

 

///Cdoe Behind

 

 

private void dataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)

{

 

if(e.Item.ItemType == ListItemType.Footer)

{

 

 

 

System.Web.UI.WebControls.DropDownList drp = new DropDownList();

drp = (DropDownList)e.Item.FindControl("listAnup");

drp.DataSource=newArrayList;//This Statement throwing exception

drp.DataBind();

}

 

}

 

 

 

 

 

 

///aspx code

 

<asp:datagrid id=dataGrid1 style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 8px" runat="server" ShowFooter="True" CaptionAlign="Top" Caption="Hello" BackColor="RosyBrown" AllowPaging="True" Height="256px" Width="70%" DataSource="<%# dataSet1 %>" PageSize="2" CellPadding="2" CellSpacing="2">

<FooterStyle ForeColor="#FFFF80" BorderColor="#E0E0E0" BackColor="Gray"></FooterStyle>

<SelectedItemStyle ForeColor="#804040" BorderColor="#FFE0C0" BackColor="Aqua"></SelectedItemStyle>

<EditItemStyle ForeColor="#FFE0C0" BackColor="#C0FFC0"></EditItemStyle>

<AlternatingItemStyle ForeColor="DarkOliveGreen" BackColor="#FFC080"></AlternatingItemStyle>

<ItemStyle ForeColor="#404040" BackColor="Khaki"></ItemStyle>

<HeaderStyle BackColor="RosyBrown"></HeaderStyle>

 

 

<Columns>

<asp:TemplateColumn HeaderText="Select">

<ItemTemplate>

<asp:Label id="labelSelectTyre" runat="server"></asp:Label>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="MTD">

<ItemTemplate>

<asp:DropDownList id="listAnup" AutoPostBack="True" runat="server" Width="150px"></asp:DropDownList>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

 

<PagerStyle VerticalAlign="Middle" ForeColor="#404000" BackColor="White" PageButtonCount="5"

Mode="NumericPages"></PagerStyle>

<PagerStyle NextPageText="Next" PrevPageText="Previous" HorizontalAlign="Center" Position="TopAndBottom"

BackColor="#D8D8DA" PageButtonCount="15" Mode="NumericPages"></PagerStyle>

 

<PagerStyle NextPageText="Next" PrevPageText="Previous"

HorizontalAlign="Center" Position="TopAndBottom" BackColor="#D8D8DA"

PageButtonCount="15" CssClass="dgridPaging"

Mode="NumericPages"></PagerStyle>

 

</asp:datagrid></form>

Posted

I have a datagrid with dropdown in my application.

I want to fill the data in dropdown by an ArrayList

for that I am using "e.Item.FindControl("DropdownId")"

but this function is returning NULL THUS I m getting exception

"Object Refrence not set to an Instance to Object",

 

Here is the code I wrote (ASP.NET 1.1)...

 

Hope I get some help from you,

 

 

 

///Cdoe Behind

 

 

private void dataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)

{

 

if(e.Item.ItemType == ListItemType.Footer)

{

 

 

 

System.Web.UI.WebControls.DropDownList drp = new DropDownList();

drp = (DropDownList)e.Item.FindControl("listAnup");

drp.DataSource=newArrayList;//This Statement throwing exception drp.DataBind();

}

 

}

 

 

 

 

 

 

///aspx code

 

<asp:datagrid id=dataGrid1 style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 8px" runat="server" ShowFooter="True" CaptionAlign="Top" Caption="Hello" BackColor="RosyBrown" AllowPaging="True" Height="256px" Width="70%" DataSource="<%# dataSet1 %>" PageSize="2" CellPadding="2" CellSpacing="2">

<FooterStyle ForeColor="#FFFF80" BorderColor="#E0E0E0" BackColor="Gray"></FooterStyle>

<SelectedItemStyle ForeColor="#804040" BorderColor="#FFE0C0" BackColor="Aqua"></SelectedItemStyle>

<EditItemStyle ForeColor="#FFE0C0" BackColor="#C0FFC0"></EditItemStyle>

<AlternatingItemStyle ForeColor="DarkOliveGreen" BackColor="#FFC080"></AlternatingItemStyle>

<ItemStyle ForeColor="#404040" BackColor="Khaki"></ItemStyle>

<HeaderStyle BackColor="RosyBrown"></HeaderStyle>

 

 

<Columns>

<asp:TemplateColumn HeaderText="Select">

<ItemTemplate>

<asp:Label id="labelSelectTyre" runat="server"></asp:Label>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="MTD">

<ItemTemplate>

<asp:DropDownList id="listAnup" AutoPostBack="True" runat="server" Width="150px"></asp:DropDownList>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

 

<PagerStyle VerticalAlign="Middle" ForeColor="#404000" BackColor="White" PageButtonCount="5"

Mode="NumericPages"></PagerStyle>

<PagerStyle NextPageText="Next" PrevPageText="Previous" HorizontalAlign="Center" Position="TopAndBottom"

BackColor="#D8D8DA" PageButtonCount="15" Mode="NumericPages"></PagerStyle>

 

<PagerStyle NextPageText="Next" PrevPageText="Previous"

HorizontalAlign="Center" Position="TopAndBottom" BackColor="#D8D8DA"

PageButtonCount="15" CssClass="dgridPaging"

Mode="NumericPages"></PagerStyle>

 

</asp:datagrid></form>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...