我在我的数据库中有以下表格:如何在GridView中使用ModalPopUpExtender?
建议日志表: ID,标题,描述。
Employee表:用户名,姓名
分部表: DivisionCode,DivisionName
我想说明表由SuggestionID,SuggestionTitle,EmployeeName和DivisionName的,当用户点击只和建议标题,将会显示一个弹出窗口和建议的描述。
因为我是ASP.NET初学者开发人员,所以我试图按照this tutorial来获得它,但我失败了。
我所做的是以下几点:
ASP.NET代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkSuggestionTitle"
Text='<%#Eval("Title") %>'
OnClick="lnkSuggestionTitle_Click">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />--%>
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Username" HeaderText="Username"
SortExpression="Username" />
<asp:BoundField DataField="DivisionName" HeaderText="Division"
SortExpression="DivisionName" />
</Columns>
</asp:GridView>
<asp:Button runat="server" ID="btnModalPopUp" style="display:none" />
<AjaxToolkit:ModalPopupExtender ID="modalPopUpExtender1"
runat="server" TargetControlID="btnModalPopUp" PopupControlID="pnlPopUp" BackgroundCssClass="modalBackground"
OkControlID="btnOk" X="20" Y="100">
</AjaxToolkit:ModalPopupExtender>
<asp:Panel runat="server" ID="pnlPopUp" CssClass="confirm-dialog">
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT dbo.SafetySuggestionsLog.ID, dbo.SafetySuggestionsLog.Title, dbo.SafetySuggestionsLog.Description, dbo.employee.Name, dbo.SafetySuggestionsLog.Username,
dbo.Divisions.DivisionName
FROM dbo.employee INNER JOIN
dbo.SafetySuggestionsLog ON dbo.employee.Username = dbo.SafetySuggestionsLog.Username INNER JOIN
dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode">
</asp:SqlDataSource>
代码隐藏:
protected void lnkSuggestionTitle_Click(object sender, EventArgs e)
{
LinkButton lnkSuggestionTitle = sender as LinkButton;
string strSuggestionTitle = lnkSuggestionTitle.Text;
string strConnectionString = ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
string strSelect = "SELECT ID, Title, Description FROM dbo.SafetySuggestionsLog";
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = strConnectionString;
SqlCommand cmdSuggestionDetails = new SqlCommand();
cmdSuggestionDetails.Connection = sqlCon;
cmdSuggestionDetails.CommandType = System.Data.CommandType.Text;
cmdSuggestionDetails.CommandText = strSelect;
cmdSuggestionDetails.Parameters.AddWithValue("@Title", strSuggestionTitle);
sqlCon.Open();
SqlDataReader dReader = cmdSuggestionDetails.ExecuteReader();
GridView1.DataSource = dReader;
GridView1.DataBind();
sqlCon.Close();
modalPopUpExtender1.Show();
}
一切都很顺利和平稳,但在网站上,当我点击其中一个标题时,我没有得到ModalPopUp。另外,我在Internet Explorer浏览器,这当我打开它,它给了我下面的描述中左下角的错误通知:
**
Sys.ArgumentNullException:值不能为空值。参数名: 元素
**
我不知道这是为什么发生。请帮忙吗?
尝试从标记中删除'DataSourceId'属性。当DataSource通过Source和'Code-Behind'指定时,DataControl无法填充。希望这有助于 – Deeptechtons 2012-02-05 05:25:34
感谢您的帮助。现在,我得到了另一个错误:Sys.ArgumentNullException:值不能为空。参数名称:元素。 – 2012-02-05 05:39:21