protected void Page_Load(object sender, EventArgs e)
{ if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowSucmobile(classid);
}
if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowFailnum(classid);
}
} public string GetSUCUrl(string classid)
{
return "Message_KF.aspx?classid=" + classid;
}
public string GetFailUrl(string classid)
{
return "Message_KF.aspx?classid=" + classid;
}
private void ShowSucmobile(string classid)
{
SqlConnection conn = new SqlConnection ("server=172.16.1.248;uid=sa;password='$eszaq!23w';database=JxtFee");
conn.Open();
SqlCommand command = new SqlCommand("SucnumMobile", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@seldate", SqlDbType.VarChar, 20);
command.Parameters.Add("@classid", SqlDbType.Int);
command.Parameters["@seldate"].Value = Convert.ToDateTime(this.DropYear.SelectedValue + "-" + this.DropMonth.SelectedValue + "-01");
command.Parameters["@classid"].Value = classid;
SqlDataAdapter sda = new SqlDataAdapter(command);
DataSet ds = new DataSet();
sda.Fill(ds);
this.GridMobile.DataSource = ds;
this.GridMobile.DataBind(); }
private void ShowFailnum(string classid)
{
SqlConnection conn = new SqlConnection("server=172.16.1.248;uid=sa;password='$eszaq!23w';database=JxtFee");
conn.Open();
SqlCommand command = new SqlCommand("FailnumMobile", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@seldate", SqlDbType.VarChar, 20);
command.Parameters.Add("@classid", SqlDbType.Int);
command.Parameters["@seldate"].Value = Convert.ToDateTime(this.DropYear.SelectedValue + "-" + this.DropMonth.SelectedValue + "-01");
command.Parameters["@classid"].Value = classid;
SqlDataAdapter sda = new SqlDataAdapter(command);
DataSet ds = new DataSet();
sda.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
<asp:TemplateField HeaderText="成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetSUCUrl(Convert.ToString(Eval("classid"))) %>'
Text=' <%# Eval("sucnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="未成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetFailUrl(Convert.ToString(Eval("classid"))) %>'
Text=' <%# Eval("failnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
执行这段代码会有个问题,不管我是点击成功数还是未成功数他都会同时调用上面两个方法,我现在想做一个判断,当我点击成功数的时候他只调用ShowSucmobile()而点击未成功数得时候他只调用 ShowFailnum()这个应该怎么做
{ if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowSucmobile(classid);
}
if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowFailnum(classid);
}
} public string GetSUCUrl(string classid)
{
return "Message_KF.aspx?classid=" + classid;
}
public string GetFailUrl(string classid)
{
return "Message_KF.aspx?classid=" + classid;
}
private void ShowSucmobile(string classid)
{
SqlConnection conn = new SqlConnection ("server=172.16.1.248;uid=sa;password='$eszaq!23w';database=JxtFee");
conn.Open();
SqlCommand command = new SqlCommand("SucnumMobile", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@seldate", SqlDbType.VarChar, 20);
command.Parameters.Add("@classid", SqlDbType.Int);
command.Parameters["@seldate"].Value = Convert.ToDateTime(this.DropYear.SelectedValue + "-" + this.DropMonth.SelectedValue + "-01");
command.Parameters["@classid"].Value = classid;
SqlDataAdapter sda = new SqlDataAdapter(command);
DataSet ds = new DataSet();
sda.Fill(ds);
this.GridMobile.DataSource = ds;
this.GridMobile.DataBind(); }
private void ShowFailnum(string classid)
{
SqlConnection conn = new SqlConnection("server=172.16.1.248;uid=sa;password='$eszaq!23w';database=JxtFee");
conn.Open();
SqlCommand command = new SqlCommand("FailnumMobile", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@seldate", SqlDbType.VarChar, 20);
command.Parameters.Add("@classid", SqlDbType.Int);
command.Parameters["@seldate"].Value = Convert.ToDateTime(this.DropYear.SelectedValue + "-" + this.DropMonth.SelectedValue + "-01");
command.Parameters["@classid"].Value = classid;
SqlDataAdapter sda = new SqlDataAdapter(command);
DataSet ds = new DataSet();
sda.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
<asp:TemplateField HeaderText="成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetSUCUrl(Convert.ToString(Eval("classid"))) %>'
Text=' <%# Eval("sucnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="未成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetFailUrl(Convert.ToString(Eval("classid"))) %>'
Text=' <%# Eval("failnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
执行这段代码会有个问题,不管我是点击成功数还是未成功数他都会同时调用上面两个方法,我现在想做一个判断,当我点击成功数的时候他只调用ShowSucmobile()而点击未成功数得时候他只调用 ShowFailnum()这个应该怎么做
{ if (Request.QueryString["Suclassid"] != null)
{
string classid = Request.QueryString["Suclassid"].ToString();
ShowSucmobile(classid);
}
if (Request.QueryString["Failclassid"] != null)
{
string classid = Request.QueryString["Failclassid"].ToString();
ShowFailnum(classid);
}
} public string GetSUCUrl(string classid)
{
return "Message_KF.aspx?Suclassid=" + classid;
}
public string GetFailUrl(string classid)
{
return "Message_KF.aspx?Failclassid=" + classid;
}
command.Parameters.Add("@classid", SqlDbType.Int);
你没有赋值然后让我们来看看你所发的题目,是2列.
HyperLink控件没有CLICK事件,我建议你可以尝试下linkbutton
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton></div>
其中的CLICK事件编写你所需要的东西
所以你页面一但回传就会重新加载这2个方法,所以肯定执行.
你把这2个方法写在不同的CLICK事件中,就应该会达到你想要的
效果了
{
string classid = Request.QueryString["classid"].ToString();
ShowSucmobile(classid);
}
if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowFailnum(classid);
}
你这个地方的判断写错了(红色的地方),你都是对“classid”进行判断,当然ShowSucmobile()、ShowFailnum()都会执行了。这是你的疏忽吧
我假设
id name age
现在我name和age都是链接按钮
我假设 现在有一行
3 张三 36不管我点
姓名:张三
还是
年龄:36
所返回的都是我所需要的id
我有了这个ID 不就可以去数据库干我想要的事情吗?
有没有必要写2个存储过程呢
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetSUCUrl(Convert.ToString(Eval("classid")))%>' Text=' <%# Eval("sucnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="未成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetFailUrl(Convert.ToString(Eval("classid")))%>' Text=' <%# Eval("failnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
==
<asp:TemplateField HeaderText="成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetSUCUrl(Convert.ToString(Eval("classid"))) + "&flag=0" %>' Text=' <%# Eval("sucnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="未成功数">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=' <%# GetFailUrl(Convert.ToString(Eval("classid")))+ "&flag=1" %>' Text=' <%# Eval("failnum") %>'> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField> protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowSucmobile(classid);
}
if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
ShowFailnum(classid);
}
}
==
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["classid"] != null)
{
string classid = Request.QueryString["classid"].ToString();
} if(Request.QueryString["flag"] != null)
{
string flag = Request.QueryString["flag"];
if(flag == "0")
{
ShowSucmobile(classid);
}
else
{
ShowFailnum(classid);
}
}
}
你直接在Response.Redirect("*.aspx?classid=获取到的值")中写