This is a migrated thread and some comments may be shown as answers.

Getting a datakeyname value after a dropdown change

5 Answers 318 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boone
Top achievements
Rank 2
Boone asked on 22 Jul 2008, 04:43 PM
I need a grid  that has a drop down in each row. When you change the drop down it grabs the ID for that row as well as the changed drop down value. I don't want the user to have to hit an edit button then a save button. I've got the look I want below but I'm struggling getting the datakey value of that row. Please help.

    <telerik:RadGrid ID="RadGrid2"   
        OnNeedDataSource="RadGrid2_NeedDataSource"   
        OnItemCommand="Lead_Click"   
        Skin="Mac"   
        Width="97%"   
        AllowSorting="True"   
        PageSize="30"   
        AllowPaging="True"   
        runat="server"   
        Gridlines="None">  
        <MasterTableView Width="100%" Summary="RadGrid table" DataKeyNames="Link_ID" AutoGenerateColumns="false">  
        <Columns> 
            <telerik:GridBoundColumn DataField="Company_Name" HeaderText="Company Name"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="City" HeaderText="City"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="State" HeaderText="State"></telerik:GridBoundColumn> 
            <telerik:GridTemplateColumn UniqueName="StageTemplate" HeaderText="Stage">  
                <ItemTemplate> 
                    <telerik:RadComboBox ID="Stage" runat="server" DataValueField="Stage_Definition" Skin="Office2007" OnInit="ddStageBound" OnSelectedIndexChanged="buttonChangeLead_Click" AutoPostBack="true">  
                        <Items> 
                            <telerik:RadComboBoxItem Value="1" Text="Pre-Approach" /> 
                            <telerik:RadComboBoxItem Value="2" Text="Approach" /> 
                            <telerik:RadComboBoxItem Value="3" Text="Presentation" /> 
                            <telerik:RadComboBoxItem Value="4" Text="Close" /> 
                            <telerik:RadComboBoxItem Value="5" Text="Completed" /> 
                        </Items> 
                    </telerik:RadComboBox> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
        </Columns> 
        </MasterTableView>     
        <PagerStyle Mode="NextPrevAndNumeric" /> 
        <ClientSettings   
            EnablePostBackOnRowClick="true" 
            AllowColumnsReorder="true" 
            ReorderColumnsOnClient="true"   
            EnableRowHoverStyle="true" > 
            <Selecting AllowRowSelect="true" /> 
        </ClientSettings> 
    </telerik:RadGrid> 
 

        protected void buttonChangeLead_Click(object source, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
            string StageID = e.Value;  
            //Need the parent grids datakeynames "Link_ID" of the row that i changed  
        }  
 

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jul 2008, 06:02 AM
Hello Boone,

Try out the following code snippet for accessing the DataKeyValue.
cs:
protected void buttonChangeLead_Click(object sender, EventArgs e)  
    {         
       RadComboBox rdcbx = (RadComboBox)sender;  
       GridDataItem itm = (GridDataItem)rdcbx.NamingContainer;  
       string StageID = itm.GetDataKeyValue("Link_ID").ToString();    
       string strtxt = rdcbx.Text;    
    }  

Thanks
Princy.
0
Boone
Top achievements
Rank 2
answered on 23 Jul 2008, 02:54 PM
Perfect, thank you. Solved another problem I had to.
0
Loi
Top achievements
Rank 1
answered on 23 Jul 2008, 04:54 PM
Hi Boone,

I have a grid with drop down list too but my situation is a little different.  I hope you can help me out here.  When a user change a value from a drop down list on the grid's row, I want to collapse or expand the table based on the value selected.  I wanted to do this through Javascript.

Do you know a way?

Thanks
0
Boone
Top achievements
Rank 2
answered on 23 Jul 2008, 06:36 PM
Loi,

You could do the same thing I am in the code I sent. Then in the back end do

  <div id="divTemp" runat="server" style="display:none;"
     Stuff here 
  </div> 
 

        protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            RadComboBox rdcbx = (RadComboBox)sender; 
            if (rdcbx.SelectedValue == "1") 
            { 
                divTemp.Style["display"] = "none"; 
                //OR divTemp.Style["display"] = ""; depending on what you want 
            } 
         } 
 

On the aspx page via JS it would be OnClientSelectedIndexChanged="JSmethod"

function dropDownChanged(sender, args) 
            { 
                if(args.getDataKeyValue("dKeyValue") == "1") //Not sure how to get the selected value. Would have to look into the documentation 
                { 
                    document.getElementById('divTemp').style.display = "none"
                } 
            } 

Hope that helps

-Boone



0
Princy
Top achievements
Rank 2
answered on 24 Jul 2008, 06:15 AM
Hello Loi,

You can check out this simple approach.

aspx:
<MasterTableView  DataSourceID="SqlDataSource1">                           
 <Columns>                  
     <telerik:GridTemplateColumn UniqueName="TemplateColumn">    
        <ItemTemplate>                      
            <asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">                    <asp:ListItem Text="No" Value="No"></asp:ListItem>                              <asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>                            </asp:DropDownList>                     
       </ItemTemplate>                  
    </telerik:GridTemplateColumn>                                           
 </Columns>                             
</MasterTableView>  


cs:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList ddl = (DropDownList)sender; 
        GridDataItem data = (GridDataItem)ddl.NamingContainer; 
        if (ddl.Text == "Yes") 
        { 
            data.Expanded = true
        } 
        else 
        { 
            data.Expanded = false
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Boone
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Boone
Top achievements
Rank 2
Loi
Top achievements
Rank 1
Share this question
or