ページに2つのグリッドビューがあります。最初のページは、ページが読み込まれたときにデータを取得し、2番目のグリッドビューはボタンがクリックされたときにデータを取得します。 2番目のグリッドビューにデータが入力される前に、最初のグリッドビューのハイパーリンクが正しく動作します。しかし、ボタンがクリックされ、2番目のグリッドビューにデータが入力されるとすぐに、最初のグリッドビューのハイパーリンクは機能しません。その外観はハイパーリンクに似ていますが、カーソルをポイントするとリンクが表示されず、URLが開きません。ただし、2番目のグリッドビューのハイパーリンクは正常に動作します。そのハイパーリンクC#:同じページの2番目のグリッドビューにデータが入力されると、最初のグリッドビューのハイパーリンクが機能しなくなる
GridViewのボタンがクリックされた後に動作しません:
<asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="Saved_Work" Style="float: left; font-size: small; position: relative;
width: 82%; position: relative; top: 0px; height: 55px; font-size: small; text-align: left;
left: 30px;" align="left">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:HyperLink ID="Continue_SavedWork" runat="server" NavigateUrl='<%# Eval("ID", "~/EditSavedJob.aspx?ID={0}") %>'
Text='<%# Eval("ID") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" HeaderText="User" SortExpression="UserID" />
<asp:BoundField DataField="Date_Created" HeaderText="Date_Created" SortExpression="Date_Created" />
</Columns>
</asp:GridView>
ボタン:
<asp:Button ID="Button1" runat="server" OnClick="FillGridView" Text="Search" Style="font-size: small;
position: relative; text-align: left; top: 0px; left: 280px; border: 1px ridge #2F10AB" />
GridViewのボタンのクリックにバインドします:
<asp:GridView ID="GridView1" runat="server" Height="27px" OnRowUpdating="EditStatus_Click"
Style="left: 120px; position: relative; width: 82%; top: 0px; text-align: center;
font-size: small;" Width="361px" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="JobNumber" HeaderText="JobNumber" />
<asp:BoundField DataField="CustomerName" HeaderText="CustomerName" />
<asp:BoundField DataField="JobLocation" HeaderText="JobLocation" />
<asp:BoundField DataField="StartDate" HeaderText="StartDate" DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("JobID", "~/JobDetails.aspx?JobID={0}") %>'
Text='Edit Job' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:HyperLink ID="Tickets" runat="server" NavigateUrl='<%# string.Format("~/Tickets.aspx?JobId={0}&JobNumber={1}",
HttpUtility.UrlEncode(Eval("JobId").ToString()), HttpUtility.UrlEncode(Eval("JobNumber").ToString())) %>'
Text='Tickets' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update Status">
<ItemTemplate>
<asp:DropDownList ID="StatusDD" runat="server" Style="position: relative; font-size: small;
left: 5%; font-family: 'Segoe UI'; border: 1px ridge #2F10AB; background-color: #F7F7F7"
AutoPostBack="True">
<asp:ListItem> </asp:ListItem>
<asp:ListItem>Submitted</asp:ListItem>
<asp:ListItem>Closed</asp:ListItem>
<asp:ListItem>Void</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" CommandName="Update" Text="Save" />
<asp:TemplateField HeaderText="Download PDF">
<ItemTemplate>
<%--<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("JobID", "~/GeneratePDF.aspx?JobID={0}") %>' Text='View' />--%>
<asp:Button ID="View" runat="server" OnClick="View_Click" Text="PDF" Style="text-align: right" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
ボタンのサーバー側のコード:
protected void FillGridView(object sender, EventArgs e)
{
GridLabel.Enabled = true;
GridLabel.Text = "Search Results";
string strConnection = ConfigurationManager
.ConnectionStrings["test_rashmiConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnection))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
StringBuilder sbCommand = new
StringBuilder("select J.JobNumber,J.Status,J.JobID,C.Name as CustomerName, C.StartDate,C.JobLocation from JobDetails J inner join CustomerDetails C on J.CustomerID=C.ID where 1=1 ");
if (CustomerName.Text != "")
{
sbCommand.Append(" AND [email protected]");
SqlParameter param = new
SqlParameter("@CustomerName", CustomerName.Text);
cmd.Parameters.Add(param);
}
if (JobNumber.Text != "")
{
sbCommand.Append(" AND [email protected]");
SqlParameter param = new
SqlParameter("@JobNumber", JobNumber.Text);
cmd.Parameters.Add(param);
}
if (FromDate.Text != "" && ToDate.Text != "")
{
sbCommand.Append(" AND C.StartDate between @FromDate and @ToDate");
SqlParameter param1 = new
SqlParameter("@FromDate", FromDate.Text);
SqlParameter param2 = new
SqlParameter("@ToDate", ToDate.Text);
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
}
if (JobLocation.Text != "")
{
sbCommand.Append(" AND C.JobLocation= @JobLocation ");
SqlParameter param = new
SqlParameter("@JobLocation", JobLocation.Text);
cmd.Parameters.Add(param);
}
sbCommand.Append(" Order by C.StartDate desc");
if (CustomerName.Text == "" && JobNumber.Text == "" && FromDate.Text == "" && ToDate.Text == "" && JobLocation.Text == "")
{
sbCommand = new StringBuilder("select top 10 J.JobNumber,J.Status,J.JobID,C.Name as CustomerName, C.StartDate,C.JobLocation from JobDetails J inner join CustomerDetails C on J.CustomerID=C.ID where 1=1 Order by C.StartDate desc");
}
cmd.CommandText = sbCommand.ToString();
cmd.CommandType = CommandType.Text;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
GridView2.DataSource = Saved_Work;
GridView2.DataBind();
}
}
Plsはaspxコードとサーバー側コードの両方を投稿します –
@MohamedNajiullah、私はコードを含む投稿を編集しました –