드롭 다운 상자에서 뭔가를 선택해야합니다. 그래서 드롭 다운 상자에서 뭔가를 선택했는지 확인하기 위해 자바 스크립트를 사용하고 있습니다. 데이터가 데이터베이스에 기록됩니다. DetailView에 단추가 있고 여기에 단추 ID에 액세스 할 수 없습니다. 드롭 다운에서 아무 것도 선택하지 않은 경우 삽입 단추를 눌렀을 때 사용자에게 경고를 보내주기를 원합니다.사용자가 드롭 다운 상자에서 선택하도록합니다.
<script type="text/javascript">
function validate() {
var flag = true;
var dropdowns = new Array(); //Create array to hold all the dropdown lists.
var gridview = document.getElementById('<%=DV_InputForm.ClientID%>'); //GridView1 is the id of ur gridview.
dropdowns = gridview.getElementsByTagName('Select'); //Get all dropdown lists contained in GridView1.
for (var i = 0; i < dropdowns.length; i++) {
if (dropdowns.item(i).value == 'Select') //If dropdown has no selected value
{
flag = false;
break; //break the loop as there is no need to check further.
}
}
if (!flag) {
alert('Please make selection from the drop-down and click the insert button again. Thanks');
document.getElementById('<%=Button1.ClientID%>').style.visibility = 'hidden';
}
return flag;
}
</script>
<RowStyle BackColor="#CCCCCC" ForeColor="#8C4510" />
</asp:DetailsView>
내가 그것을 않기 때문에 지금 컴파일 할 수없는입니다 : 드롭 다운에서 선택이 "--select 미터 환난"여기
<asp:DetailsView ID="DV_InputForm" runat="server" Height="69px" Width="763px" AutoGenerateRows="False"
CellPadding="3" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" OnItemInserting="DV_InputForm_ItemInserting"
OnModeChanging="DV_InputForm_ModeChanging" BackColor="#DEBA84" DefaultMode="Insert"
CellSpacing="2" Style="margin-top: 0px">
<Fields>
<asp:TemplateField HeaderText="Metric Name:">
<ItemTemplate>
<asp:Label ID="lblMetricName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.MetricName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_NewMetricName" DataTextField="NAME" DataValueField="NAME"
runat="server" AutoPostBack="false" Width="400" Height="25" AppendDataBoundItems="true"
DataSourceID="DD_METRIC_DS">
<asp:ListItem Text="--Select Metric Name--" Value="--Select Metric Name"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnNew" runat="server" CausesValidation="False" CommandName="New"
Text="Create New Server Monitoring" Font-Bold="True" BorderColor="#003366" BorderStyle="Groove"
Height="30px" />
</ItemTemplate>
<InsertItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Insert" OnClientClick="return validate();"
Text="Insert" />
<asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#FFFFCC" Font-Bold="True" ForeColor="#003366" />
내 자바 스크립트입니다 안 이렇게 :
<%=Button1.ClientID%>
그리고 나는 Button1 아래에 빨간 선을 얻고있다. DetailView에서 Button1에 액세스하는 방식이 잘못되었습니다.
<%=Button1.ClientID%>
질문을 업데이트하고 "삽입"버튼을 클릭하면 현재 어떤 일이 발생하는지 설명 할 수 있습니까? – jeuton