Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am not able to get the dropdown values in gridview_rowcommand.
what it the problem in that..?
Pls. help this is very urgent.
see my code.

<asp:TemplateField HeaderText="From Period" HeaderStyle-HorizontalAlign="Left">
                                  <edititemtemplate>
                                      <asp:DropDownList ID="cmbFrm" runat="server" Style="width: 150px;"
                                          DataSourceID="dsOtherDept1" DataTextField="FromPeriod" DataValueField="FromPeriod"
                                          AppendDataBoundItems="true">
                                          <asp:ListItem Text="Please Select" Value="">

                                  </edititemtemplate>
                                  <itemtemplate>
                                      <asp:Label ID="lblFrm" runat="server" Text='<%# Eval("FromPeriod") %>'>
                                  </itemtemplate>
                                   <HeaderStyle HorizontalAlign="Left" />

                               <asp:TemplateField HeaderText="To Period" HeaderStyle-HorizontalAlign="Left">
                                  <edititemtemplate>
                                      <asp:DropDownList ID="cmbTo" runat="server" Style="width: 150px;"
                                          DataSourceID="dsOtherDept1" DataTextField="ToPeriod" DataValueField="ToPeriod"
                                          AppendDataBoundItems="true">
                                          <asp:ListItem Text="Please Select" Value="">

                                  </edititemtemplate>
                                  <itemtemplate>
                                      <asp:Label ID="lblTo" runat="server" Text='<%# Eval("ToPeriod") %>'>
                                  </itemtemplate>
                                   <HeaderStyle HorizontalAlign="Left" />

                              <asp:TemplateField HeaderText="Edit" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
                                  <edititemtemplate>
                                      <asp:LinkButton ID="lbkUpdate" runat="server" CausesValidation="True" CommandName="Update"  CommandArgument='<%#Eval("emp_number") %>' Text="Update">
                                      <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel">
                                  </edititemtemplate>
                                  <itemtemplate>
                                      <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit"  CommandArgument='<%#Eval("emp_number") %>' Text="Edit">
                                  </itemtemplate>
                                  <HeaderStyle HorizontalAlign="Left" />

                              <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />


                  <asp:SqlDataSource ID="dsOtherDept1" runat="server"
                          ConnectionString="<%$ConnectionStrings:MPP%>"
                          SelectCommand="Select distinct V.emp_number as emp_number,emp_name+' '+emp_initial as name,emp_designation,Manpower_Division_ID,FromPeriod, ToPeriod from idpeapp.dbo.view_employee V inner join OtherDeptEmp O on V.emp_number = O.emp_number order by name">



Protected Sub grdDeptEmp_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdDeptEmp.RowCommand
       'Dim list As DropDownList = TryCast(e.Row.FindControl("cmbFrm"), DropDownList)
       'cmbFrm.SelectedIndex = cmbFrm.Items.IndexOf(cmbFrm.Items.FindByValue(DataBinder.Eval(e.Row.DataItem, "FromPeriod")))
       Dim emp_number As Integer = Convert.ToInt32(e.CommandArgument)
       Dim cmbFrm As DropDownList = DirectCast(grdDeptEmp.FindControl("cmbFrm"), DropDownList)
       If e.CommandName = "update" Then
           'Dim list As DropDownList = TryCast(e.Row.FindControl("cmbFrm"), DropDownList)
           'get the EmpNo of the clicked row
           'dsOtherDept1.UpdateCommand  = "update OtherDeptEmp set FromPeriod='" &  & "',ToPeriod='" & & "' where emp_number= '" & EmpNo & "'"
           'dsOtherDept1.DataBind()
       End If
   End Sub
Posted
Updated 11-Jul-11 19:40pm
v2

No, your inability to do your job is not urgent to us.

What happens exactly. Are your drop box values databound on postback ? If so, they will lose their values. If not, are you getting access to the object and not the value, or what ?
 
Share this answer
 
If you want to get the dropdownlist object under onrowcommand event.first you will have to maintain the rowindex.which will return the particular row clicked by you.so please create a ViewState Type Property to maintain the row index.

public int RowIndex
{
get
{
return ViewState["RowIndex"] != null ? Convert.ToInt32(ViewState["RowIndex"]) : -1;
}
set
{
ViewState["RowIndex"] = value;
}
}
when you will click on edit or delete button. Assign the rowindex into Property(" RowIndex")

after that By using this follwoing line of code you will get the dropdownlist Object under onrowcommand event.

if(RowIndex != -1)
{
DropDownList cmbTo = (DropDownList) GvRating.Rows[RowIndex].FindControl("cmbTo");
if(cmbTo!= null)
{
// Here you can write your statement.
}
}
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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