POSTBACK的困惑
我想取DropDownList中的SelectedValue,可是一POSTBACK就什么也没了,大家有好的办法取吗,谢谢大家
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript" type="text/javascript">
function save(index)
{
var id = index.replace('DropDownList1','hidden');
var obj = document.getElementById(index);
document.getElementById(id).value = obj.options(obj.selectedIndex).value;
alert(document.getElementById(id).value);
//document.getElementById('hidden').value += obj.options(obj.selectedIndex).value;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField HeaderText="test" DataField="test">
</asp:BoundField>
<asp:TemplateField HeaderText="反馈">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="111" Value="111"></asp:ListItem>
<asp:ListItem Text="222" Value="222"></asp:ListItem>
<asp:ListItem Text="333" Value="333"></asp:ListItem>
</asp:DropDownList>
<asp:HiddenField ID="hidden" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="操作" ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
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 System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindGridView();
}
public DataSet GetData()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("test");
dt.Rows.Add(new string[] { "111" });
dt.Rows.Add(new string[] { "222" });
dt.Rows.Add(new string[] { "333&q