How to make GridView DropDown list select the row, and execute the OnSelectedIndexchange method?












0














I hope the question I asked is accurate for I am trying to achieve. I have a GridView that is displaying data from an SQL source. I need one of the columns to be a dropdown list. I also am searching for a way to when I open the dropdown menu it selects the row then executes the added OnSelectedIndexChange event.



I am pulling the cell data of the respective selected row and submitting that data to an SQL table. Is there a way to NOT select the row and use the change of the drop down list as the identifier for the row? I ask that because there is an additional post back when selecting the row. I searching for the ability to drop the menu down, and when the new value is selected execute change event (which submits the row data to a db.)



If I have to select, then I have to select. But the biggest problem I am currently have is the dropdown value selected is not passing through to C#. Here is the Gridview and C# showing what I am doing. I have much commented out because I can't see why it won't pass through the value.



<div class="CurrentMonthTab" style ="height:350px; width:90%; margin-left:15px;  overflow-y: scroll; overflow-x: hidden">        
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
Width="100%" Font-Size = "11pt"
CellPadding="5" ClientIDMode="Static" ShowHeader="False"
HeaderStyle-BackColor="YellowGreen" DataSourceID="SqlDataSource2">
<Columns>
<asp:CommandField ShowSelectButton="True" />

<asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-Width="16%" />
<asp:BoundField DataField="UniqClient" HeaderText="UniqClient" SortExpression="UniqClient" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
<asp:BoundField DataField="Expiring_Policies" HeaderText="Expiring_Policies" ReadOnly="True" SortExpression="Expiring_Policies" ItemStyle-Width="18%" ItemStyle-Wrap="True" />
<asp:BoundField DataField="Premiums" HeaderText="Premiums" ReadOnly="True" SortExpression="Premiums" ItemStyle-Width="8%" ItemStyle-CssClass="ExpDateCSS" />
<asp:BoundField DataField="TotalPremium" HeaderText="TotalPremium" ReadOnly="True" SortExpression="TotalPremium" ItemStyle-Width="8%" />
<asp:BoundField DataField="Lines" HeaderText="Lines" SortExpression="Lines" ItemStyle-Width="20%" ReadOnly="True" />
<asp:BoundField DataField="ExpDate" HeaderText="ExpDate" ReadOnly="True" SortExpression="ExpDate" ItemStyle-Width="10%" />
<asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" ItemStyle-Width="6%" ItemStyle-CssClass="ExpDateCSS" ReadOnly="True" />
<asp:BoundField DataField="Broker_Name" HeaderText="Broker_Name" SortExpression="Broker_Name" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
<asp:TemplateField HeaderText="NameOf" SortExpression="NameOf">
<ItemTemplate>
<asp:DropDownList ID="ddlUnderWriter" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged" SelectedValue='<%# Bind("NameOf") %>' DataSourceID="SqlDataSource3" DataTextField="NameOf" DataValueField="NameOf">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UniqBroker" HeaderText="UniqBroker" ReadOnly="True" SortExpression="UniqBroker" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
</Columns>


<HeaderStyle BackColor="YellowGreen"></HeaderStyle>
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="Red" />

</asp:GridView>


Here is the GridView and I have a template field for the dropdown menu.



 protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e )
{

//TableCell client = GridView1.Rows[c.RowIndex].Cells[1];
// string Client = GridView1.SelectedRow.Cells[1].Text;//Client Name
//int UniqCNT = Int32.Parse(GridView1.SelectedRow.Cells[2].Text); //UniqClient
//string ExpPolicyNums = GridView1.SelectedRow.Cells[3].Text;
//int Ub = Int32.Parse(GridView1.SelectedRow.Cells[11].Text);//UniqBroker
//string ExperationDate = GridView1.SelectedRow.Cells[7].Text; //ExpDate
string NewUw = GridView1.SelectedRow.Cells[10].Text; //This inserts the Under Writer
/* string Company = GridView1.SelectedRow.Cells[8].Text; //Company issuer
string Broker = GridView1.SelectedRow.Cells[9].Text; //Broker_Name
string Premium = GridView1.SelectedRow.Cells[4].Text; //Premiums
string TotalPremium = GridView1.SelectedRow.Cells[5].Text; //Total premiums
string Reviewed = "No"; //Updates the DB and shows that it hasn't been reviewed by the Message Creator
//DateCreated gets inserted when record is created */
// string NewUw = ddlUnderWriter1.SelectedValue;


DateTime dateUpDated = DateTime.Now; //Inserts a dateUpdated record
if (String.IsNullOrEmpty(NewUw))
{
string empty = "empty fin box";
MessageBox.Show(empty);
}
else
{
MessageBox.Show(NewUw);
}

// int UpR = Int32.Parse(vRenewalReport.SelectedRow.Cells[9].Text); //UniqProducer. This will always submit NULL due to not
// intially receving the UniqProducer data in the GridView

/*
string query = "INSERT INTO [GTU_Apps].[dbo].[Reviewed_Renewal_Policy] (UniqClient, Client, [Expiring_Policies], Premiums, TotalPremium, UniqBroker, ExpDate, NewUw, Company, Broker_Name, Reviewed, DateUpdated) " +
"VALUES (@UniqCNT, @Client, @ExpPolicyNums, @Premium, @TotalPremium, @Ub, @ExperationDate, @NewUw, @Company, @Broker, @Reviewed, @dateUpDated)";

using (SqlConnection conn = new SqlConnection("Data Source=GTU-BDE01;Initial Catalog=GTU_Apps;Integrated Security=True"))
{
using (SqlCommand comm = new SqlCommand(query, conn))
{
comm.Parameters.AddWithValue("@UniqCNT", UniqCNT);
comm.Parameters.AddWithValue("@Client", Client);
comm.Parameters.AddWithValue("@ExpPolicyNums", ExpPolicyNums);
comm.Parameters.AddWithValue("@Premium", Premium);
comm.Parameters.AddWithValue("@TotalPremium", TotalPremium );
comm.Parameters.AddWithValue("@Ub", Ub);
comm.Parameters.AddWithValue("@ExperationDate", ExperationDate);
comm.Parameters.AddWithValue("@NewUw", NewUw);
comm.Parameters.AddWithValue("@Company", Company);
comm.Parameters.AddWithValue("@Broker", Broker);

comm.Parameters.AddWithValue("@Reviewed", Reviewed);
comm.Parameters.AddWithValue("@dateUpDated", dateUpDated);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
}*/
End(sender, e);
}


Here is the code behind. Much of this is commented out because I needed to isolate the dropdown and figure out why it wasn't passing through the value. You can see I'm checking to see if the string is null or empty. Then displaying it quickly with a messagebox for testing purposes. Even when I purposely select the row, then make the dropdown list change, it will show me it's empty. Any help would be greatly appreciated.










share|improve this question



























    0














    I hope the question I asked is accurate for I am trying to achieve. I have a GridView that is displaying data from an SQL source. I need one of the columns to be a dropdown list. I also am searching for a way to when I open the dropdown menu it selects the row then executes the added OnSelectedIndexChange event.



    I am pulling the cell data of the respective selected row and submitting that data to an SQL table. Is there a way to NOT select the row and use the change of the drop down list as the identifier for the row? I ask that because there is an additional post back when selecting the row. I searching for the ability to drop the menu down, and when the new value is selected execute change event (which submits the row data to a db.)



    If I have to select, then I have to select. But the biggest problem I am currently have is the dropdown value selected is not passing through to C#. Here is the Gridview and C# showing what I am doing. I have much commented out because I can't see why it won't pass through the value.



    <div class="CurrentMonthTab" style ="height:350px; width:90%; margin-left:15px;  overflow-y: scroll; overflow-x: hidden">        
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
    Width="100%" Font-Size = "11pt"
    CellPadding="5" ClientIDMode="Static" ShowHeader="False"
    HeaderStyle-BackColor="YellowGreen" DataSourceID="SqlDataSource2">
    <Columns>
    <asp:CommandField ShowSelectButton="True" />

    <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-Width="16%" />
    <asp:BoundField DataField="UniqClient" HeaderText="UniqClient" SortExpression="UniqClient" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
    <asp:BoundField DataField="Expiring_Policies" HeaderText="Expiring_Policies" ReadOnly="True" SortExpression="Expiring_Policies" ItemStyle-Width="18%" ItemStyle-Wrap="True" />
    <asp:BoundField DataField="Premiums" HeaderText="Premiums" ReadOnly="True" SortExpression="Premiums" ItemStyle-Width="8%" ItemStyle-CssClass="ExpDateCSS" />
    <asp:BoundField DataField="TotalPremium" HeaderText="TotalPremium" ReadOnly="True" SortExpression="TotalPremium" ItemStyle-Width="8%" />
    <asp:BoundField DataField="Lines" HeaderText="Lines" SortExpression="Lines" ItemStyle-Width="20%" ReadOnly="True" />
    <asp:BoundField DataField="ExpDate" HeaderText="ExpDate" ReadOnly="True" SortExpression="ExpDate" ItemStyle-Width="10%" />
    <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" ItemStyle-Width="6%" ItemStyle-CssClass="ExpDateCSS" ReadOnly="True" />
    <asp:BoundField DataField="Broker_Name" HeaderText="Broker_Name" SortExpression="Broker_Name" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
    <asp:TemplateField HeaderText="NameOf" SortExpression="NameOf">
    <ItemTemplate>
    <asp:DropDownList ID="ddlUnderWriter" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged" SelectedValue='<%# Bind("NameOf") %>' DataSourceID="SqlDataSource3" DataTextField="NameOf" DataValueField="NameOf">
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="UniqBroker" HeaderText="UniqBroker" ReadOnly="True" SortExpression="UniqBroker" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
    </Columns>


    <HeaderStyle BackColor="YellowGreen"></HeaderStyle>
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="Red" />

    </asp:GridView>


    Here is the GridView and I have a template field for the dropdown menu.



     protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e )
    {

    //TableCell client = GridView1.Rows[c.RowIndex].Cells[1];
    // string Client = GridView1.SelectedRow.Cells[1].Text;//Client Name
    //int UniqCNT = Int32.Parse(GridView1.SelectedRow.Cells[2].Text); //UniqClient
    //string ExpPolicyNums = GridView1.SelectedRow.Cells[3].Text;
    //int Ub = Int32.Parse(GridView1.SelectedRow.Cells[11].Text);//UniqBroker
    //string ExperationDate = GridView1.SelectedRow.Cells[7].Text; //ExpDate
    string NewUw = GridView1.SelectedRow.Cells[10].Text; //This inserts the Under Writer
    /* string Company = GridView1.SelectedRow.Cells[8].Text; //Company issuer
    string Broker = GridView1.SelectedRow.Cells[9].Text; //Broker_Name
    string Premium = GridView1.SelectedRow.Cells[4].Text; //Premiums
    string TotalPremium = GridView1.SelectedRow.Cells[5].Text; //Total premiums
    string Reviewed = "No"; //Updates the DB and shows that it hasn't been reviewed by the Message Creator
    //DateCreated gets inserted when record is created */
    // string NewUw = ddlUnderWriter1.SelectedValue;


    DateTime dateUpDated = DateTime.Now; //Inserts a dateUpdated record
    if (String.IsNullOrEmpty(NewUw))
    {
    string empty = "empty fin box";
    MessageBox.Show(empty);
    }
    else
    {
    MessageBox.Show(NewUw);
    }

    // int UpR = Int32.Parse(vRenewalReport.SelectedRow.Cells[9].Text); //UniqProducer. This will always submit NULL due to not
    // intially receving the UniqProducer data in the GridView

    /*
    string query = "INSERT INTO [GTU_Apps].[dbo].[Reviewed_Renewal_Policy] (UniqClient, Client, [Expiring_Policies], Premiums, TotalPremium, UniqBroker, ExpDate, NewUw, Company, Broker_Name, Reviewed, DateUpdated) " +
    "VALUES (@UniqCNT, @Client, @ExpPolicyNums, @Premium, @TotalPremium, @Ub, @ExperationDate, @NewUw, @Company, @Broker, @Reviewed, @dateUpDated)";

    using (SqlConnection conn = new SqlConnection("Data Source=GTU-BDE01;Initial Catalog=GTU_Apps;Integrated Security=True"))
    {
    using (SqlCommand comm = new SqlCommand(query, conn))
    {
    comm.Parameters.AddWithValue("@UniqCNT", UniqCNT);
    comm.Parameters.AddWithValue("@Client", Client);
    comm.Parameters.AddWithValue("@ExpPolicyNums", ExpPolicyNums);
    comm.Parameters.AddWithValue("@Premium", Premium);
    comm.Parameters.AddWithValue("@TotalPremium", TotalPremium );
    comm.Parameters.AddWithValue("@Ub", Ub);
    comm.Parameters.AddWithValue("@ExperationDate", ExperationDate);
    comm.Parameters.AddWithValue("@NewUw", NewUw);
    comm.Parameters.AddWithValue("@Company", Company);
    comm.Parameters.AddWithValue("@Broker", Broker);

    comm.Parameters.AddWithValue("@Reviewed", Reviewed);
    comm.Parameters.AddWithValue("@dateUpDated", dateUpDated);
    conn.Open();
    comm.ExecuteNonQuery();
    conn.Close();
    }
    }*/
    End(sender, e);
    }


    Here is the code behind. Much of this is commented out because I needed to isolate the dropdown and figure out why it wasn't passing through the value. You can see I'm checking to see if the string is null or empty. Then displaying it quickly with a messagebox for testing purposes. Even when I purposely select the row, then make the dropdown list change, it will show me it's empty. Any help would be greatly appreciated.










    share|improve this question

























      0












      0








      0







      I hope the question I asked is accurate for I am trying to achieve. I have a GridView that is displaying data from an SQL source. I need one of the columns to be a dropdown list. I also am searching for a way to when I open the dropdown menu it selects the row then executes the added OnSelectedIndexChange event.



      I am pulling the cell data of the respective selected row and submitting that data to an SQL table. Is there a way to NOT select the row and use the change of the drop down list as the identifier for the row? I ask that because there is an additional post back when selecting the row. I searching for the ability to drop the menu down, and when the new value is selected execute change event (which submits the row data to a db.)



      If I have to select, then I have to select. But the biggest problem I am currently have is the dropdown value selected is not passing through to C#. Here is the Gridview and C# showing what I am doing. I have much commented out because I can't see why it won't pass through the value.



      <div class="CurrentMonthTab" style ="height:350px; width:90%; margin-left:15px;  overflow-y: scroll; overflow-x: hidden">        
      <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
      Width="100%" Font-Size = "11pt"
      CellPadding="5" ClientIDMode="Static" ShowHeader="False"
      HeaderStyle-BackColor="YellowGreen" DataSourceID="SqlDataSource2">
      <Columns>
      <asp:CommandField ShowSelectButton="True" />

      <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-Width="16%" />
      <asp:BoundField DataField="UniqClient" HeaderText="UniqClient" SortExpression="UniqClient" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
      <asp:BoundField DataField="Expiring_Policies" HeaderText="Expiring_Policies" ReadOnly="True" SortExpression="Expiring_Policies" ItemStyle-Width="18%" ItemStyle-Wrap="True" />
      <asp:BoundField DataField="Premiums" HeaderText="Premiums" ReadOnly="True" SortExpression="Premiums" ItemStyle-Width="8%" ItemStyle-CssClass="ExpDateCSS" />
      <asp:BoundField DataField="TotalPremium" HeaderText="TotalPremium" ReadOnly="True" SortExpression="TotalPremium" ItemStyle-Width="8%" />
      <asp:BoundField DataField="Lines" HeaderText="Lines" SortExpression="Lines" ItemStyle-Width="20%" ReadOnly="True" />
      <asp:BoundField DataField="ExpDate" HeaderText="ExpDate" ReadOnly="True" SortExpression="ExpDate" ItemStyle-Width="10%" />
      <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" ItemStyle-Width="6%" ItemStyle-CssClass="ExpDateCSS" ReadOnly="True" />
      <asp:BoundField DataField="Broker_Name" HeaderText="Broker_Name" SortExpression="Broker_Name" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
      <asp:TemplateField HeaderText="NameOf" SortExpression="NameOf">
      <ItemTemplate>
      <asp:DropDownList ID="ddlUnderWriter" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged" SelectedValue='<%# Bind("NameOf") %>' DataSourceID="SqlDataSource3" DataTextField="NameOf" DataValueField="NameOf">
      </asp:DropDownList>
      </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="UniqBroker" HeaderText="UniqBroker" ReadOnly="True" SortExpression="UniqBroker" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
      </Columns>


      <HeaderStyle BackColor="YellowGreen"></HeaderStyle>
      <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="Red" />

      </asp:GridView>


      Here is the GridView and I have a template field for the dropdown menu.



       protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e )
      {

      //TableCell client = GridView1.Rows[c.RowIndex].Cells[1];
      // string Client = GridView1.SelectedRow.Cells[1].Text;//Client Name
      //int UniqCNT = Int32.Parse(GridView1.SelectedRow.Cells[2].Text); //UniqClient
      //string ExpPolicyNums = GridView1.SelectedRow.Cells[3].Text;
      //int Ub = Int32.Parse(GridView1.SelectedRow.Cells[11].Text);//UniqBroker
      //string ExperationDate = GridView1.SelectedRow.Cells[7].Text; //ExpDate
      string NewUw = GridView1.SelectedRow.Cells[10].Text; //This inserts the Under Writer
      /* string Company = GridView1.SelectedRow.Cells[8].Text; //Company issuer
      string Broker = GridView1.SelectedRow.Cells[9].Text; //Broker_Name
      string Premium = GridView1.SelectedRow.Cells[4].Text; //Premiums
      string TotalPremium = GridView1.SelectedRow.Cells[5].Text; //Total premiums
      string Reviewed = "No"; //Updates the DB and shows that it hasn't been reviewed by the Message Creator
      //DateCreated gets inserted when record is created */
      // string NewUw = ddlUnderWriter1.SelectedValue;


      DateTime dateUpDated = DateTime.Now; //Inserts a dateUpdated record
      if (String.IsNullOrEmpty(NewUw))
      {
      string empty = "empty fin box";
      MessageBox.Show(empty);
      }
      else
      {
      MessageBox.Show(NewUw);
      }

      // int UpR = Int32.Parse(vRenewalReport.SelectedRow.Cells[9].Text); //UniqProducer. This will always submit NULL due to not
      // intially receving the UniqProducer data in the GridView

      /*
      string query = "INSERT INTO [GTU_Apps].[dbo].[Reviewed_Renewal_Policy] (UniqClient, Client, [Expiring_Policies], Premiums, TotalPremium, UniqBroker, ExpDate, NewUw, Company, Broker_Name, Reviewed, DateUpdated) " +
      "VALUES (@UniqCNT, @Client, @ExpPolicyNums, @Premium, @TotalPremium, @Ub, @ExperationDate, @NewUw, @Company, @Broker, @Reviewed, @dateUpDated)";

      using (SqlConnection conn = new SqlConnection("Data Source=GTU-BDE01;Initial Catalog=GTU_Apps;Integrated Security=True"))
      {
      using (SqlCommand comm = new SqlCommand(query, conn))
      {
      comm.Parameters.AddWithValue("@UniqCNT", UniqCNT);
      comm.Parameters.AddWithValue("@Client", Client);
      comm.Parameters.AddWithValue("@ExpPolicyNums", ExpPolicyNums);
      comm.Parameters.AddWithValue("@Premium", Premium);
      comm.Parameters.AddWithValue("@TotalPremium", TotalPremium );
      comm.Parameters.AddWithValue("@Ub", Ub);
      comm.Parameters.AddWithValue("@ExperationDate", ExperationDate);
      comm.Parameters.AddWithValue("@NewUw", NewUw);
      comm.Parameters.AddWithValue("@Company", Company);
      comm.Parameters.AddWithValue("@Broker", Broker);

      comm.Parameters.AddWithValue("@Reviewed", Reviewed);
      comm.Parameters.AddWithValue("@dateUpDated", dateUpDated);
      conn.Open();
      comm.ExecuteNonQuery();
      conn.Close();
      }
      }*/
      End(sender, e);
      }


      Here is the code behind. Much of this is commented out because I needed to isolate the dropdown and figure out why it wasn't passing through the value. You can see I'm checking to see if the string is null or empty. Then displaying it quickly with a messagebox for testing purposes. Even when I purposely select the row, then make the dropdown list change, it will show me it's empty. Any help would be greatly appreciated.










      share|improve this question













      I hope the question I asked is accurate for I am trying to achieve. I have a GridView that is displaying data from an SQL source. I need one of the columns to be a dropdown list. I also am searching for a way to when I open the dropdown menu it selects the row then executes the added OnSelectedIndexChange event.



      I am pulling the cell data of the respective selected row and submitting that data to an SQL table. Is there a way to NOT select the row and use the change of the drop down list as the identifier for the row? I ask that because there is an additional post back when selecting the row. I searching for the ability to drop the menu down, and when the new value is selected execute change event (which submits the row data to a db.)



      If I have to select, then I have to select. But the biggest problem I am currently have is the dropdown value selected is not passing through to C#. Here is the Gridview and C# showing what I am doing. I have much commented out because I can't see why it won't pass through the value.



      <div class="CurrentMonthTab" style ="height:350px; width:90%; margin-left:15px;  overflow-y: scroll; overflow-x: hidden">        
      <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
      Width="100%" Font-Size = "11pt"
      CellPadding="5" ClientIDMode="Static" ShowHeader="False"
      HeaderStyle-BackColor="YellowGreen" DataSourceID="SqlDataSource2">
      <Columns>
      <asp:CommandField ShowSelectButton="True" />

      <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-Width="16%" />
      <asp:BoundField DataField="UniqClient" HeaderText="UniqClient" SortExpression="UniqClient" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
      <asp:BoundField DataField="Expiring_Policies" HeaderText="Expiring_Policies" ReadOnly="True" SortExpression="Expiring_Policies" ItemStyle-Width="18%" ItemStyle-Wrap="True" />
      <asp:BoundField DataField="Premiums" HeaderText="Premiums" ReadOnly="True" SortExpression="Premiums" ItemStyle-Width="8%" ItemStyle-CssClass="ExpDateCSS" />
      <asp:BoundField DataField="TotalPremium" HeaderText="TotalPremium" ReadOnly="True" SortExpression="TotalPremium" ItemStyle-Width="8%" />
      <asp:BoundField DataField="Lines" HeaderText="Lines" SortExpression="Lines" ItemStyle-Width="20%" ReadOnly="True" />
      <asp:BoundField DataField="ExpDate" HeaderText="ExpDate" ReadOnly="True" SortExpression="ExpDate" ItemStyle-Width="10%" />
      <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" ItemStyle-Width="6%" ItemStyle-CssClass="ExpDateCSS" ReadOnly="True" />
      <asp:BoundField DataField="Broker_Name" HeaderText="Broker_Name" SortExpression="Broker_Name" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
      <asp:TemplateField HeaderText="NameOf" SortExpression="NameOf">
      <ItemTemplate>
      <asp:DropDownList ID="ddlUnderWriter" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged" SelectedValue='<%# Bind("NameOf") %>' DataSourceID="SqlDataSource3" DataTextField="NameOf" DataValueField="NameOf">
      </asp:DropDownList>
      </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="UniqBroker" HeaderText="UniqBroker" ReadOnly="True" SortExpression="UniqBroker" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
      </Columns>


      <HeaderStyle BackColor="YellowGreen"></HeaderStyle>
      <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="Red" />

      </asp:GridView>


      Here is the GridView and I have a template field for the dropdown menu.



       protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e )
      {

      //TableCell client = GridView1.Rows[c.RowIndex].Cells[1];
      // string Client = GridView1.SelectedRow.Cells[1].Text;//Client Name
      //int UniqCNT = Int32.Parse(GridView1.SelectedRow.Cells[2].Text); //UniqClient
      //string ExpPolicyNums = GridView1.SelectedRow.Cells[3].Text;
      //int Ub = Int32.Parse(GridView1.SelectedRow.Cells[11].Text);//UniqBroker
      //string ExperationDate = GridView1.SelectedRow.Cells[7].Text; //ExpDate
      string NewUw = GridView1.SelectedRow.Cells[10].Text; //This inserts the Under Writer
      /* string Company = GridView1.SelectedRow.Cells[8].Text; //Company issuer
      string Broker = GridView1.SelectedRow.Cells[9].Text; //Broker_Name
      string Premium = GridView1.SelectedRow.Cells[4].Text; //Premiums
      string TotalPremium = GridView1.SelectedRow.Cells[5].Text; //Total premiums
      string Reviewed = "No"; //Updates the DB and shows that it hasn't been reviewed by the Message Creator
      //DateCreated gets inserted when record is created */
      // string NewUw = ddlUnderWriter1.SelectedValue;


      DateTime dateUpDated = DateTime.Now; //Inserts a dateUpdated record
      if (String.IsNullOrEmpty(NewUw))
      {
      string empty = "empty fin box";
      MessageBox.Show(empty);
      }
      else
      {
      MessageBox.Show(NewUw);
      }

      // int UpR = Int32.Parse(vRenewalReport.SelectedRow.Cells[9].Text); //UniqProducer. This will always submit NULL due to not
      // intially receving the UniqProducer data in the GridView

      /*
      string query = "INSERT INTO [GTU_Apps].[dbo].[Reviewed_Renewal_Policy] (UniqClient, Client, [Expiring_Policies], Premiums, TotalPremium, UniqBroker, ExpDate, NewUw, Company, Broker_Name, Reviewed, DateUpdated) " +
      "VALUES (@UniqCNT, @Client, @ExpPolicyNums, @Premium, @TotalPremium, @Ub, @ExperationDate, @NewUw, @Company, @Broker, @Reviewed, @dateUpDated)";

      using (SqlConnection conn = new SqlConnection("Data Source=GTU-BDE01;Initial Catalog=GTU_Apps;Integrated Security=True"))
      {
      using (SqlCommand comm = new SqlCommand(query, conn))
      {
      comm.Parameters.AddWithValue("@UniqCNT", UniqCNT);
      comm.Parameters.AddWithValue("@Client", Client);
      comm.Parameters.AddWithValue("@ExpPolicyNums", ExpPolicyNums);
      comm.Parameters.AddWithValue("@Premium", Premium);
      comm.Parameters.AddWithValue("@TotalPremium", TotalPremium );
      comm.Parameters.AddWithValue("@Ub", Ub);
      comm.Parameters.AddWithValue("@ExperationDate", ExperationDate);
      comm.Parameters.AddWithValue("@NewUw", NewUw);
      comm.Parameters.AddWithValue("@Company", Company);
      comm.Parameters.AddWithValue("@Broker", Broker);

      comm.Parameters.AddWithValue("@Reviewed", Reviewed);
      comm.Parameters.AddWithValue("@dateUpDated", dateUpDated);
      conn.Open();
      comm.ExecuteNonQuery();
      conn.Close();
      }
      }*/
      End(sender, e);
      }


      Here is the code behind. Much of this is commented out because I needed to isolate the dropdown and figure out why it wasn't passing through the value. You can see I'm checking to see if the string is null or empty. Then displaying it quickly with a messagebox for testing purposes. Even when I purposely select the row, then make the dropdown list change, it will show me it's empty. Any help would be greatly appreciated.







      c# asp.net gridview dropdown






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 13:24









      swapmeet_Lou

      308




      308
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413037%2fhow-to-make-gridview-dropdown-list-select-the-row-and-execute-the-onselectedind%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413037%2fhow-to-make-gridview-dropdown-list-select-the-row-and-execute-the-onselectedind%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen