Solved

When I  programmatically open a datagrid row in edit mode my dropdown in the edittemplate does not show.

Posted on 2009-07-09
3
449 Views
Last Modified: 2013-11-07
I have a datagrid with a radiobutton and several other columns of data.  When the user clicks a radio button that selected row is programmatically put into edit mode, one of the columns has a dropdown which is located in an EditItemTemplate but the drop down does not show it only shows as a textbox.  Does any one have an idea why the dropdown doesnt show?
ASPX Page

 

<asp:DataGrid TabIndex="3" id="dgPeople" runat="server" CellSpacing="2" GridLines="None" BorderColor="#666699" BorderWidth="1px" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="False" Width="100%">

<Columns>

<asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="10%" ItemStyle-Width="10%" HeaderStyle-CssClass="clsGridHeaderText" HeaderStyle HorizontalAlign="Center">

  <HeaderTemplate>					<font color="#165A8E">&nbsp;Select&nbsp;</font>

</HeaderTemplate>

<ItemTemplate>

  <asp:RadioButton ID="radSelect" OnCheckedChanged="SelectOnlyOne" GroupName='<%# DataBinder.Eval(Container, "DataItem.UserID")%>' AutoPostBack="True" Runat="server"></asp:RadioButton>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="First Name" HeaderStyle-CssClass="clsGridHeaderText" 

SortExpression="FirstName" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" HeaderStyle-Wrap="False" ItemStyle-Wrap="False">

<ItemTemplate>&nbsp;

<asp:Label id="lblFirstName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FirstName")%>' ></asp:Label>

</ItemTemplate>

<EditItemTemplate>

                            <asp:TextBox runat="Server" id="txtFirstName" Text='<%# DataBinder.Eval(Container.DataItem, "FirstName")%>' />

                          </EditItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Discipline" HeaderStyle-CssClass="clsGridHeaderText" SortExpression="Discipline" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Wrap="False" ItemStyle-Wrap="False">

<ItemTemplate><asp:Label ID="discipline" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Discipline")%>'></asp:Label>

</ItemTemplate>

<EditItemTemplate>						  <asp:DropDownList id="drpDiscipline" runat="server">			 <asp:ListItem Value="1">Physical Therapist</asp:ListItem>

 <asp:ListItem Value="2">Recreational Therapist</asp:ListItem>

<asp:ListItem Value="3">Registered Nurse</asp:ListItem>

<asp:ListItem Value="4">Occupational Therapist, Registered</asp:ListItem>

</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:DataGrid>

 

VB Code Behind

 

THIS IS CALLED WHEN USER CLICKS ON A RADIO BUTTON

Public Sub SelectOnlyOne(ByVal sender As Object, ByVal e As System.EventArgs)

 

      Dim pDTPeople As DataTable

     'THIS IS WHERE THE ROW GETS PUT INTO EDIT MODE BASED ON A ROW INDEX

     'RETURNED BY SETRADIOBUTTON

      'Call SetRadioButton the first time to get the row selected

      dgPeople.EditItemIndex = SetRadioButton(sender, e)

 

      'Load the data from ViewState in to the Dataset object.

      gfpSaveOrLoadGridViewState(pDTPeople, dgPeople.ID, "LOAD")

 

      'Fill datagrid with data stored in session with corresponding pageindex.

      Call mfpBindGrid(False, 0, pDTPeople, True)

 

      'Call SetRadioButton a second time to set the selection on the radio button

      SetRadioButton(sender, e)

 

 End Sub

 

Private Function SetRadioButton(ByVal sender As Object, ByVal e As System.EventArgs) As Integer

 

      Dim intRow As Integer = -1

 

      Dim m_ClientID As String = ""

      Dim rb As New RadioButton

 

      rb = CType(sender, RadioButton)

      m_ClientID = rb.ClientID

      rb = CType(sender, RadioButton)

      m_ClientID = rb.ClientID

 

      For Each i As DataGridItem In dgPeople.Items

        rb = CType(i.FindControl("radSelect"), RadioButton)

        rb.Checked = False

        If (m_ClientID = rb.ClientID) Then

          rb.Checked = True

 

          Response.Write(rb.GroupName & "<BR>")

          intRow = i.ItemIndex

        End If

      Next

 

      Return intRow

 

    End Function

Open in new window

0
Comment
Question by:udsmr
  • 2
3 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24824304
Hi,

I don't have access to my dev box at the moment, but what if you added an eval to bind the selected item for the dropdown? See code.

/Carl.
<asp:TemplateColumn HeaderText="Discipline" HeaderStyle-CssClass="clsGridHeaderText" SortExpression="Discipline" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Wrap="False" ItemStyle-Wrap="False">

    <ItemTemplate>

        <asp:Label ID="discipline" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Discipline")%>'>

        </asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

        <asp:DropDownList id="drpDiscipline" runat="server" SelectedItem='<%# DataBinder.Eval(Container, "DataItem.Discipline")%>'>

            <asp:ListItem Value="1">Physical Therapist</asp:ListItem>

            <asp:ListItem Value="2">Recreational Therapist</asp:ListItem>

            <asp:ListItem Value="3">Registered Nurse</asp:ListItem>

            <asp:ListItem Value="4">Occupational Therapist, Registered</asp:ListItem>

        </asp:DropDownList>

    </EditItemTemplate>

</asp:TemplateColumn>

Open in new window

0
 

Author Comment

by:udsmr
ID: 24826342
That didn't work.  I was running several other tests and it looks like when you click the radio button to put the row into edit mode it doesn't actually load the controls that are in the EditItemTemplate it loads what looks like textboxs (no dropdown).  I was working on the same page with a second datagrid  this new grid caused a post back and the 1st grid referenced above reloaded and the drop down showed but the data in the grid was missing because the data was not reloaded during this postback.
0
 

Accepted Solution

by:
udsmr earned 0 total points
ID: 24853766
I moved on and reworked my page never came up with a solution
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now