Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all, I want to get value from dropdownlist inside gridview, i tried its loop through the gridview but not able to get the value from dropdownlist, i placed the code below.. please help me thanks ...

code:
C#
function checkUpdateOption() {

            var gvET = document.getElementById("<%= GridView1.ClientID %>");
            var rCount = gvET.rows.length;
            alert(rCount);

            for (var rowIdx=1;rowIdx<=rCount-1;rowIdx++) {
            

 var cell = gvET.rows[rowIdx].cells[0].getElementsByTagName("*")[0].value;
               
 alert(cell);


            }
            return false;
        }



In Alert box it display "on" value
Posted

Instead i suggest use jQuery
Attach CssClass MyGridView to your GridView and class called MyDropDown to DropDownList

then,
C#
$('.MyGridView').find('tr').each
(
    function()
    {
        var CurrentDrownValue=$(this).find('.MyDropDown').attr('value');

    }
);
 
Share this answer
 
Hi there,

Bellow you can see a simple example that is using a GridView where each row has a cell with a dropdown item.
Each time you click a cell from the GridView (except the cells with the dropdown inside) you will get a message with the current dropdown value from the selected row.
I hope this will help you!


XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head>
<title>Dummy test</title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {
        $("#usersGridView td").click(function () {
            if ($(this).find("select").length) {
                return;
            }
            else {
                var selectedRow = $(this).parent();
                var selectedOptionValue = $(selectedRow).find("select option:selected").val();
                alert("The selected row has rate: " +selectedOptionValue);
            }
        });
    });

</script>

</head>
<body>

    <form id="myForm" runat="server">
      <asp:SqlDataSource runat="server" ID="MyDataSouce"
         ConnectionString="Data Source=localhost;Initial Catalog=Users;Integrated Security=True;"
         DataSourceMode = "DataReader"
         SelectCommand = "select [Name], [Age] from [Users]">
       </asp:SqlDataSource>

      <asp:GridView ID="usersGridView"
          Runat="server"
          DataSourceID="MyDataSouce"
          AutoGenerateColumns="false" >
      <Columns>
       <asp:BoundField DataField = "Name" HeaderText = "Name"/>
       <asp:BoundField DataField = "Age" HeaderText = "Age" />
       <asp:TemplateField HeaderText="Rate">
            <ItemTemplate>
                <select>
                  <option value="10">10%</option>
                  <option value="20">20%</option>
                  <option value="30">30%</option>
                  <option value="40">40%</option>
                </select>
            </ItemTemplate>
        </asp:TemplateField>
      </Columns>

      </asp:GridView>
    </form>

</body>
</html>
 
Share this answer
 
Comments
Skvignesh 1-Feb-13 23:17pm    
thanks for reply, but i want to get all value in button onclick event.I try this
Is this not possible using just JavaScript??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900