Dropdownlist inside detailsview--selectedindexchanged event

HI,
    I have a question here,I havea detailsview,inside which i have a dropdownlist.what i want todo is
Wen i click on any item inside dropdownlist,i want to capture wat its indexvalue is?and that too before data is submitted.I am trying to achieve this in insertitemtemplate and edititemtemplate.
HOw can i capture the selectedindexchanged event of dropdownlist and how it can be fired?I have to capture this to find the currently selected value in dropdownlist..

Please help
LVL 1
DevsolutionsAsked:
Who is Participating?
 
PHDConnect With a Mentor Commented:
sorry but I do my best but I don't understand what you try to do.
My first language in french ...

But you want to catch the value of the dropdownlist when opening window in the javascript function you just need to do it with the getelementbyid function
0
 
rodmjayCommented:
when you mean submitted, do you mean before it is posted back to server or before it is inserted or updated into the database?

here is how you can access the variable inside a detials view

dim index as integer = ctype(dv.FindControl("cmbSomeDropdown"), DropDownList).SelectedIndex
int index = ((DropDownList)dv.FindControl("cmbSomeDropdown")).SelectedIndex

You may need to alter this code to make sure that the cmbSomeDropdown is null before trying to reference the SelectedIndex

if you need to get the value before the form is submitted, then you will need to use javascript

If this doesnt work for you then let me know
0
 
DevsolutionsAuthor Commented:
hi rodmjay,
              Thanks for the response.actually i am trying to capture the id of item in dropdownlist on click of button but before postbacking,i m opening a popup window on click of the button through javascript code...and have to pass this templateid onto that page,but this is done in insertitemtemplate and edititemtemplate of detailsview.
Nnow explainig wat i want to achieve,I have a dropdownlist having some items in it.wen i open insert mode detailsview,i select an item in dropdownlist and i have to fetch that items id somehow before i submit data or a postback happens,, so that can be pased thru javascript onto another wiondow that i m opening on click event of a button.
how can i do that?


Thanks
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
PHDCommented:
Hello,

Here is a dropdownlist example :
    <asp:DropDownList ID="DropDownList1" runat="server" onchange="javascript:openwindow()">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:DropDownList>

then in the page load you can register this script :

 protected void Page_Load(object sender, EventArgs e)
    {
   
        ClientScript.RegisterClientScriptBlock(this.GetType(),"script_openwindow","<script type=text/javascript> function openwindow() " +
   "{ var value =   document.getElementById('" + DropDownList1.ClientID + "').value ; " +
   "     window.open('mypage.aspx?index=' + value ); " +
   " }</script>");

    }

this script open w new window passing the value of the selected item of dropdownlist. You have to catch this value in the new page.
If this page is an aspx one you can do that with Request.QueryString["index"];

Hope this help,
0
 
PHDCommented:
the link of the new windows lokks like : http://www.mypage.aspx?index=2.

0
 
DevsolutionsAuthor Commented:
HI PHD,
       tHANKS A lot fr teh response,i m not very gud at javascript,
had a question,will this dropdownlist1 inside detailsview work in pageload as it gets bound only wen detailsview comes into picture or shud i use this whole code at event where i m binding detailsview?
i appreciate ur help
thanks
0
 
PHDCommented:
in the page load you only register the script to the page.
the call to this function is made when you change the dropdownlist.

normaly you can use this code as I did ...
0
 
DevsolutionsAuthor Commented:
Oh i am unable to fetch that event that u say wen i change teh dropdownlist because that dropdownlist is inside the detailsview and i cant fire that event and capture the id,my motive was also to fetch the id at selectedindexchanged event of that dropdownlist and then passing it as request.querysting thru javascript only.can u help me firing event inside detailsview somehow.
thanks a lot
0
 
PHDCommented:
Paste your code please
0
 
DevsolutionsAuthor Commented:
sure
here is aspx page and dropdownlist i m talking of is ddltemplate


<%@ Page Language="C#"  ValidateRequest="false"   MasterPageFile="~/ContentAdmin/MasterPage.master" AutoEventWireup="true" CodeFile="../Page_Codes/Newsletter.aspx.cs" Inherits="ContentAdmin_pages_Newsletter" %>

<%@ Register Src="../controls/TextEditor.ascx" TagName="TextEditor" TagPrefix="uc2" %>
<%@ Register TagPrefix="imageLibrary"  Namespace="Radio.ContentAdmin.WebControls" %>
<%@ Register Src="../controls/CalendarClock.ascx" TagName="CalendarClock" TagPrefix="uc1" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" ID="Newsletter" runat="server">
<script language="javascript" type="text/javascript">
function NewWindowHtml()
{
window.open("Newsletter_Html.aspx");
}
function OpenwindowClub()
{
    if(document.getElementById("ctl00_ContentPlaceHolder1_hdnId"))
        {
            var hdvValue = document.getElementById("ctl00_ContentPlaceHolder1_hdnId").value;
            window.open("Newsletter_club.aspx?Id="+hdvValue+"&value=HTML");
        }
}
function NewWindowText()
{
window.open("NewsletterText.aspx");
}
function OpenWindowTextClub()
{
        if(document.getElementById("ctl00_ContentPlaceHolder1_hdnId"))
        {
            var hdvValue = document.getElementById("ctl00_ContentPlaceHolder1_hdnId").value;
            window.open("Newsletter_club_Text.aspx?Id="+hdvValue+"&value=TEXT");
        }
}
function OPenWindowCodeText()
{
 if(document.getElementById("ctl00_ContentPlaceHolder1_hdnId"))
        {
            var hdvValue = document.getElementById("ctl00_ContentPlaceHolder1_hdnId").value;
            window.open("Newsletter_club_Text.aspx?Id="+hdvValue+"&value=CODE");
        }
}
function OpenwindowCodeHtml()
{
  if(document.getElementById("ctl00_ContentPlaceHolder1_hdnId"))
        {
            var hdvValue = document.getElementById("ctl00_ContentPlaceHolder1_hdnId").value;
            window.open("Newsletter_club.aspx?Id="+hdvValue+"&value=CODE");
           //d.document.open('text/plain').write(document.documentElement.outerHTML);
            //window.close();
             
        }
}



</script>

<div id="Newsletter admin">
               
<fieldset>
<legend>Newsletter Info</legend>
<table border="0" style="background-color:#F7F6F3; color:#333333">
                <tr>
                    <td style="width:50%">
                        <p><strong>You can create new or manage the newsletters for this station</strong></p>
                     </td>
                    <td></td>
                    <td style="width: 142px"></td>
                    </tr>
                    <tr>
                    <td style="height: 24px">Choose Newsletter
                    </td>
                    <td style="height: 24px">
                        <asp:DropDownList ID="drpNewsletter"  DataSourceID="srcGrid" AutoPostBack="true"   runat="server" Width="250px" OnSelectedIndexChanged="drpNewsletter_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td style="width: 142px; height: 24px;"></td>
                </tr>
                <tr>
                <td><p>What would you like to do?</p></td>
                <td><asp:LinkButton ID="btnManage" CausesValidation="false" runat="server" Text="Manage Existing Newsletters" OnClick="btnManage_Click"></asp:LinkButton></td>
                <td style="width: 142px"><asp:LinkButton ID="btnCreate" CausesValidation ="false" runat="server" Text="Create New Newsletter" OnClick="btnCreateNew_Click"></asp:LinkButton></td>
                </tr>
            </table>
    <asp:Literal ID="ltrPopup" runat="server"></asp:Literal></fieldset>
    <asp:HiddenField ID="customerValue" runat="server" />
    <asp:HiddenField ID="ImageWidth" runat="server" />
    <asp:HiddenField ID="ImageHeight" runat="server" />
    <asp:HiddenField ID="hdnId" runat="server" />

</div>
<table><tr ><td colspan="3" style="width: 403px" >
<asp:Panel ID="pnlGrid" runat="server">

<asp:GridView ID="gridNewsletter"  AutoGenerateColumns="false" runat="server" DataKeyNames="NewsletterId"  AllowPaging="True" AllowSorting="True" BackColor="Silver" PageSize="5" Width="835px" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" ForeColor="#404040" DataSourceID="srcGrid"  OnSelectedIndexChanged="gridNewsletter_SelectedIndexChanged" OnRowDeleted="gridNewsletter_RowDeleted" OnSelectedIndexChanging="gridNewsletter_SelectedIndexChanging" OnRowDeleting="gridNewsletter_RowDeleting"  OnRowCommand="gridNewsletter_RowCommand" >
    <PagerStyle BorderStyle="Double" />
    <HeaderStyle BackColor="White" Font-Bold="True" Font-Underline="True" />
    <Columns>
             
             <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                   <asp:Label ID="lblNewsletterName" runat="server" Text='<%# Bind("Name") %>' />
                 </ItemTemplate>
                 <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
             </asp:TemplateField>
             
             <asp:TemplateField HeaderText="SendDate">
                <ItemTemplate>
                    <asp:Label ID="lblNewsletterStartDate" runat="server" Text='<%# Bind("SendDate") %>' />
                </ItemTemplate>
                 <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
             </asp:TemplateField>
             <asp:CommandField  ShowDeleteButton="True" ShowSelectButton="True" SelectText="View"  />
    </Columns>
   
</asp:GridView>
</asp:Panel>
</td></tr>

<tr><td>

<asp:Panel ID="pnlDetailsView" runat="server">

 <asp:DetailsView  AutoGenerateRows="false" DataKeyNames="NewsletterId"   ID="dvNewsletter" runat="server" FieldHeaderStyle-Font-Bold="true" HeaderStyle-Font-Bold="true"
 HeaderStyle-ForeColor="gray" HeaderText="News Detail" ForeColor="#404040" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" DataSourceID="srcDetailsView" Width="835px" BackColor="Silver"
  OnItemInserting="dvNewsletter_ItemInserting" RowStyle-Wrap="true"  EnableViewState="true" OnItemUpdated="dvNewsletter_ItemUpdated"  OnItemCommand="dvNewsletter_ItemCommand" OnItemUpdating="dvNewsletter_ItemUpdating"
   OnItemInserted="dvNewsletter_ItemInserted" >
 <Fields>
    <asp:TemplateField HeaderText="Name:">
    <HeaderStyle HorizontalAlign="Left" />
       <EditItemTemplate>
            <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name")%>' EnableViewState="true" />
       </EditItemTemplate>
       
       <InsertItemTemplate>
             <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name")%>' EnableViewState="true"/>
       </InsertItemTemplate>
       <ItemTemplate>
               <asp:Label ID="lblName" runat="server" Text='<%# Bind("Name")%>' EnableViewState="true"/>
       </ItemTemplate>
       
    </asp:TemplateField>
   
    <asp:TemplateField HeaderText="newsid" Visible="false">
    <EditItemTemplate>
     <asp:TextBox ID="txtId" runat="server" Text='<%# Bind("NewsletterId")%>' />
   
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblId" runat="server" Text='<%# Bind("NewsletterId")%>'></asp:Label>
   
    </ItemTemplate>
    </asp:TemplateField>
   
   <asp:TemplateField HeaderText="First Line:">
   <HeaderStyle HorizontalAlign="Left" />
        <EditItemTemplate>
            <asp:TextBox ID="txtFirstLine" runat="server" Text='<%# Bind("FirstLine")%>' />
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:TextBox ID="txtFirstLine" runat="server" Text='<%# Bind("FirstLine")%>' />
        </InsertItemTemplate>
        <ItemTemplate>
             <asp:label  ID="lblFirstLine" runat="server" Text='<%# Bind("FirstLine")%>' />
        </ItemTemplate>
     
    </asp:TemplateField>
 
   
    <asp:TemplateField HeaderText="CustomerLinkSettings:" ItemStyle-Wrap="true">
   <HeaderStyle HorizontalAlign="Left" />
        <EditItemTemplate>
        <table>
        <tr>
         
        <td>
            <asp:DropDownList ID="drpImageWidth" SelectedValue='<%# Bind("ImageWidth") %>' runat="server" DataSourceID="drpListDataWidth" DataTextField="AdWidth" DataValueField="AdWidth"  ></asp:DropDownList>
        </td>
            <td>
       <asp:DropDownList ID="drpimgHeight" SelectedValue='<%# Bind("ImageHeight") %>' runat="server" DataSourceID="drpListHeight" DataTextField="AdHeight" DataValueField="AdHeight"></asp:DropDownList>
        </tr> </table>
        </EditItemTemplate>
        <InsertItemTemplate>
            <table>
        <tr>
        <td>
            <asp:DropDownList SelectedValue='<%# Bind("ImageWidth") %>'  ID="drpImageWidth" runat="server" DataSourceID="drpListDataWidth" DataTextField="AdWidth" DataValueField="AdWidth" ></asp:DropDownList>
        </td>
            <td>
       <asp:DropDownList SelectedValue='<%# Bind("ImageHeight") %>' ID="drpimgHeight" runat="server" DataSourceID="drpListHeight" DataTextField="AdHeight" DataValueField="AdHeight" ></asp:DropDownList>
       </td>
       
        </tr>   </table>
        </InsertItemTemplate>
        <ItemTemplate>
        <table>
        <tr>
          <td colspan="2">
            <asp:Label ID="lblAdLink" runat="server" Text='<%# Bind("CustomerLink")%>'  />
         </td> </tr>
         <tr>
        <td style="width:50%">
            <asp:Label ID="lblWidth" runat="server" Text="ImageWidth" ></asp:Label>
            <asp:DropDownList SelectedValue='<%# Bind("ImageWidth") %>' ID="drpImageWidth" runat="server" DataSourceID="drpListDataWidth" DataTextField="AdWidth" DataValueField="AdWidth"  >
            </asp:DropDownList>
        </td>
            <td style="width:50%">
           
            <asp:Label ID="lblHeight" runat="server" Text="ImageHeight" EnableViewState="true"></asp:Label>
           
       <asp:DropDownList SelectedValue='<%# Bind("ImageHeight") %>' ID="drpimgHeight" runat="server" DataSourceID="drpListHeight" DataTextField="AdHeight" DataValueField="AdHeight"  ></asp:DropDownList>
       </td>
       
        </tr></table>
       
        </ItemTemplate>
     
    </asp:TemplateField>
   
   
   
   
    <asp:TemplateField HeaderText="Add Image:">
    <HeaderStyle HorizontalAlign="Left" />
        <EditItemTemplate>
         <table><tr>
          <td>
          <a id="linkHtml" onclick="javascript:NewWindowHtml()" title="PreView HTML Version:>>" href="#" > View HTML Version:>></a>
          </td>
         
          <td>
          <a id="linkText" onclick="javascript:NewWindowText()" title="PreView Text Version:>>" href="#" > View Text Version :>></a>
          </td>
          </tr>
          <tr><td>
          <asp:label ID="lblData" runat="server" Text="You will have to save the Data to fetch the code.You can only preview the page."></asp:label>
          </td></tr>
         
          </table>
        </EditItemTemplate>
         <InsertItemTemplate>
             <table><tr>
             
          <td>
          <a id="linkHtml" onclick="javascript:NewWindowHtml()" title="PreView HTML Version:>>"  href="#"> View HTML Version:>></a>
          </td>
          <td>
          <a id="linkText" onclick="javascript:NewWindowText()" title="PreView Text Version:>>"  href="#"> View Text Version :>></a>
         
          </td>
          </tr>
          <tr><td>
          <asp:label ID="lblData" runat="server" Text="You will have to save the Data to fetch the code.You can only preview the page."></asp:label>
          </td></tr>
         
         
          </table>
          </InsertItemTemplate>
         <ItemTemplate>
         <table><tr><td colspan="4">
              <asp:Label ID="lblImageUrl" runat="server" Text='<%# Bind("ImageUrl") %>'></asp:Label>
          </td></tr>
          <tr>
          <td>
         
         <a id="linkClubHtml" onclick="javascript:OpenwindowClub()" href="#" >View Newsletter HtML Page:>></a>
          </td>
          <td>
          <a id="linkCodeHtml" onclick="javascript:OpenwindowCodeHtml()" href="#">View HTML Version Code:>></a>
          </td>
          <td>
          <a id="linkText" onclick="javascript:OpenWindowTextClub()" title="View Text Version:>>"  href="#"> View Newsletter Text Version :>></a>
          </td>
          <td>
          <a id="linkCodeText" onclick="javascript:OPenWindowCodeText()" href="#">View Text Version Code:>></a>
          </td>
          </tr></table>
           </ItemTemplate>
           </asp:TemplateField>
           
           <asp:TemplateField HeaderText="SendDate" SortExpression="SendDate">
    <HeaderStyle HorizontalAlign="Left" />
             <EditItemTemplate>
             <uc1:CalendarClock ID="cc1" runat="server" SelectedDate='<%# Bind("SendDate") %>' />
              </EditItemTemplate>
              <InsertItemTemplate>
                <uc1:CalendarClock ID="cc1" runat="server" SelectedDate='<%# Bind("SendDate") %>' />
              </InsertItemTemplate>
                  <ItemTemplate>
                       <asp:Label ID="lblCalender" runat="server" Text='<%# Bind("SendDate") %>'></asp:Label>
                   </ItemTemplate>
   </asp:TemplateField>
    <asp:TemplateField HeaderText="Content:">
    <HeaderStyle HorizontalAlign="Left" />
        <EditItemTemplate>
            <uc2:TextEditor ID="txtContent" runat="server" Text='<%# Bind("Content")%>' />
        </EditItemTemplate>
        <InsertItemTemplate>
            <uc2:TextEditor ID="txtContent" runat="server" Text='<%# Bind("Content")%>' />
        </InsertItemTemplate>
        <ItemTemplate>
             <asp:label  ID="lblContent" runat="server" Text='<%# Bind("Content")%>' />
        </ItemTemplate>
       
    </asp:TemplateField>
    <asp:TemplateField HeaderText="TemplateName">
    <InsertItemTemplate>
    <asp:DropDownList SelectedValue='<%# Bind("TemplateId") %>' ID="templateddl" DataSourceID="drpListTemplate" Width="160" runat="server" DataValueField="TemplateId" DataTextField="TemplateName" OnSelectedIndexChanged="templateddl_SelectedIndexChanged" AutoPostBack="true"  ></asp:DropDownList>
    </InsertItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList SelectedValue='<%# Bind("TemplateId") %>' ID="templateddl" runat="server" DataSourceID="drpListTemplate" Width="160" DataValueField="TemplateId" DataTextField="TemplateName" OnSelectedIndexChanged="templateddl_SelectedIndexChanged" AutoPostBack="true" ></asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:DropDownList SelectedValue='<%# Bind("TemplateId") %>' ID="templateddl" runat="server"  Enabled="false" DataSourceID="drpListTemplate" Width="160" DataValueField="TemplateId" DataTextField="TemplateName" ></asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
   
    <asp:CommandField ShowEditButton="True" ShowInsertButton="True" InsertText="Add New" />
 
 </Fields>
     <FieldHeaderStyle Font-Bold="True" />
     <HeaderStyle Font-Bold="True" ForeColor="ControlDark" />

</asp:DetailsView>
</asp:Panel>
</td></tr>
</table>


<asp:SqlDataSource ID="srcgrid" OnSelecting="Populate" DeleteCommand="sp_Newsletter_Delete" DeleteCommandType="StoredProcedure" SelectCommand="sp_NewsLetterListAll" SelectCommandType="StoredProcedure"  ConnectionString="<%$ ConnectionStrings:CorusRadioGlobalSqlServer %>" runat="server"  >
<DeleteParameters>
<asp:Parameter Name="NewsletterId" Type="int32"  />
</DeleteParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="srcDetailsView" OnInserted="srcDetailsView_Inserted"    InsertCommand="sp_Newsletter_AddNew" InsertCommandType="StoredProcedure" SelectCommand="sp_NewsletterInfo" SelectCommandType="StoredProcedure" UpdateCommand="sp_Newsletter_Update" UpdateCommandType="StoredProcedure"  ConnectionString="<%$ ConnectionStrings:CorusRadioGlobalSqlServer %>"  runat="server" OnSelecting="srcDetailsView_Selecting" >
<InsertParameters>
<asp:Parameter Name="NewsletterId" Type="int32" Direction="Output" />
<asp:Parameter Name="StationId" Type="int32"  />
<asp:Parameter Name="Name" Type="string" />
<asp:Parameter Name="FirstLine" Type="string"  />
<asp:Parameter Name="ImageUrl" Type="string"  />
<asp:Parameter Name="Content" Type="string" />
<asp:Parameter Name="SendDate" Type="DateTime"  />
<asp:Parameter Name="ImageWidth" Type="int32" />
<asp:Parameter Name="ImageHeight" Type="int32" />
<asp:Parameter Name="CustomerLink" Type="string"  />
<asp:Parameter Name="TemplateId" Type="Int32" />
</InsertParameters>


<UpdateParameters>
<asp:Parameter Name="StationId" Type="int32"  />
<asp:Parameter Name="Name" Type="string" />
<asp:Parameter Name="FirstLine" Type="string"  />
<asp:Parameter Name="ImageUrl" Type="string"  />
<asp:Parameter Name="Content" Type="string"  />
<asp:Parameter Name="SendDate" Type="DateTime"  />
<asp:Parameter Name="ImageWidth" Type="int32" />
<asp:Parameter Name="ImageHeight" Type="int32" />
<asp:Parameter Name="CustomerLink" Type="string"  />
<asp:Parameter Name="NewsletterId" Type="Int32" />
<asp:Parameter Name="TemplateId" Type="Int32" />
</UpdateParameters>

</asp:SqlDataSource>

<asp:SqlDataSource ID="drpListDataWidth" runat="server" ConnectionString="<%$ ConnectionStrings:CorusRadioGlobalSqlServer %>"  SelectCommand="sp_NewsletterAdSpecWidth"  ProviderName="<%$ ConnectionStrings:CorusRadioGlobalSqlServer.ProviderName %>" SelectCommandType="StoredProcedure">
   
</asp:SqlDataSource>
<asp:SqlDataSource ID="drpListTemplate" runat="server" ConnectionString="<%$ ConnectionStrings:CorusRadioGlobalSqlServer %>" SelectCommand="sp_TemplateListAll" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

<asp:SqlDataSource ID="drpListHeight" runat="server" ConnectionString="<%$ ConnectionStrings:CorusRadioGlobalSqlServer %>" SelectCommand="sp_NewsletterAdSpecHeight"  SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</asp:Content>

0
 
DevsolutionsAuthor Commented:
and code behind is
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Corus.ApplicationBlocks.Data;
using Radio.ContentAdmin.WebControls;
using Radio.ContentAdmin;
using System.Data.SqlClient;

using Radio.ContentAdmin.BusinessLogicLayer;



public partial class ContentAdmin_pages_Newsletter : System.Web.UI.Page
{
      #region Global variables

        public User cmsUser;
        public MembershipUser logUser;
        int stationId;
        string stationcallLetter;
        int newsletterId;

    #endregion;

      #region Events

    /// <summary>
    /// Page load event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
       
        #region PageLoad
        protected void Page_Load(object sender, EventArgs e)
        {
            //Authentication checked
            if (Page.User.Identity.IsAuthenticated)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "script_openwindow", "<script type=text/javascript> function openwindow() " +
               "{ var value =   document.getElementById('" + templateddl.ClientID + "').value ; " +
               "     window.open('mypage.aspx?index=' + value ); " +
               " }</script>");
                logUser = Membership.GetUser(User.Identity.Name);

                cmsUser = Radio.ContentAdmin.BusinessLogicLayer.User.GetUserByUserId(Int32.Parse(logUser.ProviderUserKey.ToString()));
                stationId = cmsUser.CurrentStationID;
                Station station = Station.GetStationByStationID(stationId);
                stationcallLetter = station.CallLetter;
            }
            else
            {
                Response.Redirect("~/ContentAdmin/Pages/login.aspx");
            }
            if (!Page.IsPostBack)
            {
                //Populating Dropdownlist
                PopulatedrpNewsletter();
                gridNewsletter.Visible = false;
                dvNewsletter.Visible = false;

            }
            ltrPopup.Text = "";
        }
        #endregion;

        /// <summary>
        /// Method called on clcik of manage newsletter button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///

        #region Manage Newsletter
        protected void btnManage_Click(object sender, EventArgs e)
        {
            dvNewsletter.Visible = false;
            gridNewsletter.DataBind();
            gridNewsletter.Visible = true;
        }
        #endregion;

        /// <summary>
        /// Method called when create new Newsletter is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        #region Create New Newsletter
        protected void btnCreateNew_Click(object sender, EventArgs e)
        {
            dvNewsletter.ChangeMode(DetailsViewMode.Insert);
            gridNewsletter.Visible = false;
            dvNewsletter.Visible = true;
        }
        #endregion;


        /// <summary>
        /// Event fired when index is changing for a gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

         #region grid Selected IndexChanging
        protected void gridNewsletter_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {

            int SelectedIndex = e.NewSelectedIndex;
            string selectedNewsletterId = gridNewsletter.DataKeys[SelectedIndex].Value.ToString();
            hdnId.Value = selectedNewsletterId;
            newsletterId = Convert.ToInt32(selectedNewsletterId);
            dvNewsletter.DataBind();
            drpNewsletter.SelectedValue = selectedNewsletterId;
        }
        #endregion;
        /// <summary>
        /// Event fired when a row in gridview is clicked to view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
         
         #region gridSelectedIndexChanged
        protected void gridNewsletter_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.dvNewsletter.ChangeMode(DetailsViewMode.ReadOnly);
            this.dvNewsletter.Visible = true;
            if (dvNewsletter.Rows.Count != 0)
            {
                DropDownList drpImageWidth = (DropDownList)(dvNewsletter.Rows[2].Cells[1].FindControl("drpImageWidth"));

                DropDownList drpImageHeight = (DropDownList)(dvNewsletter.Rows[2].Cells[1].FindControl("drpimgHeight"));

                drpImageHeight.SelectedItem.Selected = true;
                drpImageWidth.SelectedItem.Selected = true;
            }
        }
        #endregion;

       
        /// <summary>
        /// event fired when an item is selected from dropdownlist
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        #region Dropdownlist selectedIndexChanged
        protected void drpNewsletter_SelectedIndexChanged(object sender, EventArgs e)
        {
            dvNewsletter.Visible = true;
            string NewsletterId = drpNewsletter.SelectedItem.Value;
            hdnId.Value = NewsletterId;
            newsletterId = Convert.ToInt32(NewsletterId);
            dvNewsletter.DataBind();
            dvNewsletter.ChangeMode(DetailsViewMode.ReadOnly);

        }
        #endregion;

    protected void templateddl_SelectedIndexChanged(object sender, EventArgs e)
    {
       
    }
       /// <summary>
       /// event fired when a newsletter has been created
       /// </summary>
       /// <param name="sender"></param>
        /// <param name="e"></param>

        #region Create New Newsletter-- insert event
        protected void dvNewsletter_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            dvNewsletter.ChangeMode(DetailsViewMode.Insert);
            DropDownList drpImageWidth = (DropDownList)(dvNewsletter.Rows[2].Cells[1].FindControl("drpImageWidth"));
            int Width = Convert.ToInt32(drpImageWidth.SelectedItem.Text);
            DropDownList drpImageHeight = (DropDownList)(dvNewsletter.Rows[2].Cells[1].FindControl("drpImgHeight"));
            int Height = Convert.ToInt32(drpImageHeight.SelectedItem.Text);
            string adlink = @"http://ad.ca.doubleclick.net/jump/"+stationcallLetter+".site112.tmus;sz="+Width+"x"+Height+";ord="+Timestamp().Ticks+"?";
            //string adlink = @"http://ad.ca.doubleclick.net/jump/" + stationcallLetter + ".site112.tmus;sz=" + Width + "x" + Height + ";ord=" + Timestamp().Ticks + "?";
            string imageurllink = @"http://ad.ca.doubleclick.net/ad/" + stationcallLetter + ".site112.tmus;sz=" + Width + "x" + Height + ";ord=" + Timestamp().Ticks + "?";
            ImageWidth.Value = Width.ToString();
            ImageHeight.Value = Height.ToString();
            srcDetailsView.InsertParameters["ImageUrl"].DefaultValue = imageurllink;
            //((TextBox)(dvNewsletter.Rows[6].Cells[1].FindControl("txtAdLink"))).Text = adlink;
            srcDetailsView.InsertParameters["CustomerLink"].DefaultValue = adlink;
            srcDetailsView.InsertParameters["StationId"].DefaultValue = stationId.ToString();
            customerValue.Value = adlink;
            e.Values.Add("StationID", stationId);
        }
        #endregion;

        /// <summary>
        /// Method after the item has been inserted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        #region Inserted Item
        protected void dvNewsletter_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            gridNewsletter.Visible = true;
            gridNewsletter.DataBind();
            PopulatedrpNewsletter();
            drpNewsletter.SelectedValue = newsletterId.ToString();
            dvNewsletter.ChangeMode(DetailsViewMode.ReadOnly);
            dvNewsletter.Visible = true;
           
        }
        #endregion;

       #region DatasourceItemInserted
    protected void srcDetailsView_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        SqlParameter param = new SqlParameter("@NewsletterId", SqlDbType.Int);
        param.Direction = ParameterDirection.Output;
        newsletterId = Convert.ToInt32(e.Command.Parameters[0].Value);
        hdnId.Value = newsletterId.ToString();
    }
    #endregion;
        /// <summary>
        /// event fired if cancel button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
         
        #region ItemCommand
        protected void dvNewsletter_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            dvNewsletter.Visible = true;
            if (hdnId.Value != null&&hdnId.Value != string.Empty&&hdnId.Value != "")
            {
                newsletterId = Convert.ToInt32(hdnId.Value);
            }

            if (e.CommandName == "Cancel")
            {
                dvNewsletter.ChangeMode(DetailsViewMode.ReadOnly);
            }
            if (e.CommandName == "Edit")
            {
                this.dvNewsletter.ChangeMode(DetailsViewMode.Edit);
                this.dvNewsletter.Visible = true;
            }
            if (e.CommandName == "Update")
            {
               // newsletterId = Convert.ToInt32(hdnId.Value);
            }
        }
        #endregion;

        /// <summary>
        /// Method when row has been deleted from  grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
         
        #region delete Row
        protected void gridNewsletter_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            newsletterId = -1;
            if (gridNewsletter.Rows.Count != 0)
            {
                PopulatedrpNewsletter();
            }
        }

        /// <summary>
        /// Method called when row is deleting
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gridNewsletter_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
        int rowDelete = e.RowIndex;
        if (dvNewsletter.DataKey.Value != null)
        {
            if (gridNewsletter.DataKeys[rowDelete].Value.ToString() == dvNewsletter.DataKey.Value.ToString())
            {
                e.Cancel = true;
                ltrPopup.Text = "<script>alert('U cant delete the newsletter,if details are being displayed');</script>";
            }
        }
        else
        {
            ltrPopup.Text = "";
        }
        }

        #endregion;

        /// <summary>
        /// Method to Update the detailsView values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        #region Update DetailsView
        protected void dvNewsletter_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            try
            {
                dvNewsletter.ChangeMode(DetailsViewMode.Edit);
                newsletterId = Convert.ToInt32(dvNewsletter.SelectedValue);
                dvNewsletter.Visible = true;
                srcDetailsView.UpdateParameters["StationId"].DefaultValue = stationId.ToString();
                srcDetailsView.UpdateParameters["NewsletterId"].DefaultValue = dvNewsletter.SelectedValue.ToString();
                DropDownList drpImageWidth = (DropDownList)(dvNewsletter.Rows[2].Cells[1].FindControl("drpImageWidth"));
                int Width = Convert.ToInt32(drpImageWidth.SelectedItem.Text);
                ImageWidth.Value = Width.ToString();
                DropDownList drpImageHeight = (DropDownList)(dvNewsletter.Rows[2].Cells[1].FindControl("drpImgHeight"));
                int Height = Convert.ToInt32(drpImageHeight.SelectedItem.Text);
                ImageHeight.Value = Height.ToString();
                //string adlink = @"http://ad.ca.doubleclick.net/jump/" + stationcallLetter + ".site112.tmus/newsletter;sz="+Width+"x"+Height+";ord="+Timestamp().Ticks+"?";
                string adlink = @"http://ad.ca.doubleclick.net/jump/" + stationcallLetter + ".site112.tmus;newsletter;sz=" + Width + "x" + Height + ";ord=" + Timestamp().Ticks + "?";
                string imageurllink = @"http://ad.ca.doubleclick.net/ad/" + stationcallLetter + ".site112.tmus;newsletter;sz=" + Width + "x" + Height + ";ord=" + Timestamp().Ticks + "?";
               
               
                srcDetailsView.UpdateParameters["CustomerLink"].DefaultValue = adlink;
                srcDetailsView.UpdateParameters["ImageUrl"].DefaultValue = imageurllink;
                customerValue.Value = adlink;
               
               
            }
            catch (Exception ex)
            {
                Response.Write(ex.Source + ex.StackTrace + ex.Message);
            }

        }
        /// <summary>
        /// event fired when a particular newsletter has been edited or updated
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        #region Update Item
        protected void dvNewsletter_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
           
            gridNewsletter.Visible = true;
            gridNewsletter.DataBind();
            PopulatedrpNewsletter();
            drpNewsletter.SelectedValue = newsletterId.ToString();
            dvNewsletter.ChangeMode(DetailsViewMode.ReadOnly);
            dvNewsletter.DataBind();
        }
        #endregion;

      public DateTime Timestamp()
        {
            return DateTime.Now;
        }
        #endregion;

       
       
        /// <summary>
        /// Method called when row has been selsected in a gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
     
        #region GridRowCommand
        protected void gridNewsletter_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (dvNewsletter == null)
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string IndexValue = gridNewsletter.DataKeys[index].Value.ToString();
                //srcDetailsView.InsertParameters["NewsletterId"].DefaultValue = IndexValue;
                newsletterId = Convert.ToInt32(IndexValue);
                dvNewsletter.ChangeMode(DetailsViewMode.ReadOnly);
                dvNewsletter.Visible = true;
            }
            else if (e.CommandName == "Select")
            {
                int index = Convert.ToInt32(e.CommandArgument);

            }

        }
        #endregion;

        /// <summary>
        /// Method for setting teh select parameter for detailview datasource
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        #region Detailsview Datasource
        protected void srcDetailsView_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            //e.Command.Parameters.Add(new SqlParameter("@StationId", SqlDbType.Int));
            //e.Command.Parameters["@StationId"].Value = stationId;
            SqlParameter param = new SqlParameter("@NewsletterId", SqlDbType.Int);
            param.Direction = ParameterDirection.Input;
            e.Command.Parameters.Add(param);
            param.Value = newsletterId;
           // e.Command.Parameters["@NewsletterId"].Value = newsletterId;
        }
    //protected void srcDetailsView_Updating(object sender, SqlDataSourceCommandEventArgs e)
    //{
    //    e.Command.Parameters.Add(new SqlParameter("@NewsletterId", SqlDbType.Int));
    //    e.Command.Parameters["@NewsletterId"].Value = newsletterId;
    //    e.Command.Parameters.Add(new SqlParameter("@StationId", SqlDbType.Int));
    //    e.Command.Parameters["@StationId"].Value = stationId;
    //}
        #endregion;

        /// <summary>
        /// method for setting select parameters for gridview datasource
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        #region Onselecting datasource for grid
        protected void Populate(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.Parameters.Add(new SqlParameter("@StationId", SqlDbType.Int));
            e.Command.Parameters["@StationId"].Value = stationId;
        }
        #endregion;

       
      #endregion;

    #region Public Methods

    /// <summary>
        /// Method to populate Dropdownlist for newsletters
        /// </summary>
        public void PopulatedrpNewsletter()
        {
            drpNewsletter.DataSourceID = "srcgrid";
            drpNewsletter.DataTextField = "Name";
            drpNewsletter.DataValueField = "NewsletterId";
            drpNewsletter.DataBind();
        }
        #endregion;

    }





0
 
PHDCommented:
Hello,

Here is a procedure that should work.

In the pre_render event of the dropdownlist in the detailview add this code :

 ClientScript.RegisterClientScriptBlock(this.GetType(), "script_openwindow", "<script type=text/javascript> function openwindow() " +
"{ var value =   document.getElementById('" + ((DropDownList)sender).ClientID + "').value ; " +
"     window.open('mypage.aspx?index=' + value ); " +
" }</script>");

Add this attributes to your drodownlist : onchange="javascript:openwindow()"

so when your dropdownlist is visible you can change the selected item and a new winodw is open with value of the dropdownlist in the query string.

Hope this work for you.

0
 
PHDCommented:
Here is my code that is working in my machine :

<form id="form1" runat="server">
    <div>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="u_id"
            DataSourceID="SqlDataSource1" Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="u_id" HeaderText="u_id" InsertVisible="False" ReadOnly="True"
                    SortExpression="u_id" />
                <asp:BoundField DataField="u_babybel_user" HeaderText="u_babybel_user" SortExpression="u_babybel_user" />
                <asp:BoundField DataField="u_nom" HeaderText="u_nom" SortExpression="u_nom" />
                <asp:BoundField DataField="u_password" HeaderText="u_password" SortExpression="u_password" />
                <asp:BoundField DataField="u_mail" HeaderText="u_mail" SortExpression="u_mail" />
                <asp:BoundField DataField="u_User_NT" HeaderText="u_User_NT" SortExpression="u_User_NT" />
                <asp:BoundField DataField="u_portefolio" HeaderText="u_portefolio" SortExpression="u_portefolio" />
                <asp:TemplateField HeaderText="u_groupe_id" SortExpression="u_groupe_id">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" onchange="javascript:openwindow()" runat="server" DataSourceID="SqlDataSource1"
                            DataTextField="g_nom" DataValueField="g_id" OnPreRender="DropDownList1_PreRender">
                        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:e-vision editusConnectionString %>"
                            SelectCommand="select * from syn_groupes"></asp:SqlDataSource>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("u_groupe_id") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("u_groupe_id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CheckBoxField DataField="u_responsable" HeaderText="u_responsable" SortExpression="u_responsable" />
                <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:e-vision editusConnectionString %>"
            InsertCommand="insert into syn_utilisateurs (u_nom) values (@u_nom)" SelectCommand="select * from syn_utilisateurs"
            UpdateCommand="update syn_utilisateurs set u_nom=@u_nom">
            <UpdateParameters>
                <asp:Parameter Name="u_nom" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="u_nom" />
            </InsertParameters>
        </asp:SqlDataSource>
   
    </div>
    </form>
0
 
PHDCommented:
the code behind :

 protected void Page_Load(object sender, EventArgs e)
    {
    }
   
 protected void DropDownList1_PreRender(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptBlock(this.GetType(), "script_openwindow", "<script type=text/javascript> function openwindow() " +
"{ var value =   document.getElementById('" + ((DropDownList)sender).ClientID + "').value ; " +
"     window.open('mypage.aspx?index=' + value ); " +
" }</script>");
    }
0
 
DevsolutionsAuthor Commented:
I had a querstion for u,m sorry dint check this yesterday.U have used here event onchange in dropdownlist and prerender is opening up new window,however i have  a concern here:
I just want to capture the value of item in dropdownlist here,which i want to pass when i click on a button not when i change an item in dropdownlist.Just as when i change an item in dropdowlist nothing as new window shows up,its just that i shud be able to capture the value of item now selected as item.selected does which i cant right now as i can t fine selectedindex changed ...
So just fetching teh item value here then passing it thru javascript function which i have already written and is opening up window when i click on a button..
So can i write something as event in dropdownlist which can fetch me selectedindex of dropdownlist without using server side event selectedindexchanged.

Thanks,please help i hope this explains
0
 
PHDCommented:
I think you have to know that id of the control at design time is not the same as at runtime.

so the javascirpt function getlementbyid does not work if you give the id of the cotnrol at design time.

In runtime you have somethinf like dropdownlist.ClientID this give you the id of the control when html will rendered.
I think you have to adapt your script that you regsiter.

Hope this is what you want ...
0
 
DevsolutionsAuthor Commented:
yes this is wat i m trying to do now,however i was just wondering how can i use one variable that i fetch in javascript function in my code behind page?i mean just setting var id = document.getelementbyid("ddltemplate").options[""].value;
and then using this var somewhere in code behind class,is it posible?
0
 
DevsolutionsAuthor Commented:
Hi PHD,
              I have found the solution but partially difft responses of urs match altogether the solution of my problem.Thanks a lot for being helpful.i have solved this using:
simple javascript function and capturing the selected value of dropdwolist using
function NewWindowHtml()
{
var templateddl = document.getElementById("ctl00_ContentPlaceHolder1_dvNewsletter_templateddl");
       if(templateddl)
        {
            var templateValue = templateddl.options[templateddl.selectedIndex].value;
            window.open("Newsletter_Html.aspx?templateId="+templateValue);
        }
}
This is then fetched into popup or child window...
But i thank u for all the help,here are ur points
0
All Courses

From novice to tech pro — start learning today.