我已动态创建数据表绑定到网格视图。在每一行中,我都添加了我在网格视图中定义的按钮。现在我希望该按钮调用另一个按钮单击事件并对值进行修改。这可能吗?这是我的代码:
<asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnTest" runat="server" CommandName="odzemi" CssClass="button2" OnClick="btnTest_Click" Text="-" Width="100px" Font-Bold="True" />
<asp:Button ID="Button15" Visible="false" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void btnTest_Click(object sender, EventArgs e)
{
Session["Counter1"] = newValue;
Session["Counter"] = newValue;
if (Session["Markici"] != null || Session["Markici"] != null)
{
var clickedRow = ((Button)sender).NamingContainer as GridViewRow;
var clickedIndex = clickedRow.RowIndex;
/*decimal*/ old = dtCurrentTable.Rows[clickedIndex].Field<decimal>("Kolicina");
decimal oldIznos = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkIznos");
decimal VkDanok = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkDanok");
string Cena1 = dtCurrentTable.Rows[clickedIndex].Field<string>("Cena1");
int TarifaID = dtCurrentTable.Rows[clickedIndex].Field<Int16>("TarifaID");
// decimal pocentDanok0 = 0.0m;
// decimal pocentDanok1 = 0.18m;
// decimal pocentDanok2 = 0.5m;
//int oldValue = int.Parse(old);
/* decimal*/ newValue = old - 1; //
Label37.Text = newValue.ToString();
decimal newIznos = oldIznos - Convert.ToDecimal(Cena1);
dtCurrentTable.Rows[clickedIndex].SetField("Kolicina", newValue.ToString());
dtCurrentTable.Rows[clickedIndex].SetField("VkIznos", newIznos.ToString());
} //我想在这里打电话给btn_test点击并调整他的价值
protected void Button7_Click(object sender, EventArgs e)
{
if (GridView2.Rows.Count == 0)
{
Response.Redirect("MasiGradskaKafanak1.aspx");
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["string2"].ConnectionString);
Session["Counter"] = counter;
Label11.Text = counter.ToString();
// Label11.Text = Session["kolicina2"].ToString(); //ViewState["count"].ToString(); //
if (reader.Read())
{
Label35.Text = (string)reader["pkid"].ToString();
Label12.Text = (string)reader["Artikal"].ToString();
Label33.Text = (string)reader["Vid"].ToString();
Label34.Text = (string)reader["EdMera"].ToString();
Label14.Text = (string)reader["TarifaID"].ToString();
Label13.Text = (string)reader["Cena1"].ToString();
//iznos
decimal mnoz = Convert.ToDecimal(Label11.Text) * Convert.ToDecimal(Label13.Text);
Label17.Text = mnoz.ToString();
decimal.Parse(Label17.Text);
decimal cena;
cena = Convert.ToDecimal(Label13.Text);
decimal kolicina;
kolicina = Convert.ToDecimal(Label11.Text);
decimal iznos;
iznos = Convert.ToDecimal(Label17.Text);
Session["cena1"] = Label13.Text;
Session["iznos1"] = Label17.Text;
if (Label14.Text == "0")
{
decimal pocentDanok = 0.0m;
vkdanok1 = Convert.ToDecimal(vkdanok1) + Convert.ToDecimal(cena) * Convert.ToDecimal(kolicina) * Convert.ToDecimal(pocentDanok) / (1 + Convert.ToDecimal(pocentDanok));
vkdanok1 = Math.Truncate(vkdanok1 * 10000m) / 10000m;
Label18.Text = vkdanok.ToString();//vkdanok
}
else if (Label14.Text == "1")
{
decimal pocentDanok = 0.18m;
vkdanok1 = (vkdanok1) + Convert.ToDecimal(cena) * Convert.ToDecimal(kolicina) * Convert.ToDecimal(pocentDanok) / (1 + Convert.ToDecimal(pocentDanok));
vkdanok1 = Math.Truncate(vkdanok1 * 10000m) / 10000m;
Label18.Text = vkdanok1.ToString();//VkDanok
}
else if (Label14.Text == "2")
{
decimal pocentDanok = 0.5m;
vkdanok1 = Convert.ToDecimal(vkdanok1) + Convert.ToDecimal(cena) * Convert.ToDecimal(kolicina) * Convert.ToDecimal(pocentDanok) / (1 + Convert.ToDecimal(pocentDanok));
vkdanok1 = Math.Truncate(vkdanok1 * 10000m) / 10000m;
Label18.Text = vkdanok1.ToString();//vkdanok
}
conn.Close();
}
DataTable dtCurrentTable = (DataTable)ViewState["Markici"];
if (Label37.Text == "0")
{
dtCurrentTable.Rows[0]["Kolicina"] = Label11.Text;
}
else if (Label37.Text != "0")
{
Counter1 = Counter1 + 1;
dtCurrentTable.Rows[0]["Kolicina"] = Convert.ToInt32(Label37.Text) + Counter1;// Label37.Text;//Convert.ToInt32(Label37.Text) + 3;
}
dtCurrentTable.Rows[0]["Artikal"] = Label12.Text;
dtCurrentTable.Rows[0]["Cena1"] = Label13.Text;
dtCurrentTable.Rows[0]["VkIznos"] = Label17.Text;
dtCurrentTable.Rows[0]["VkDanok"] = Label18.Text;
dtCurrentTable.Rows[0]["EdMera"] = Label34.Text;
dtCurrentTable.Rows[0]["ArtikalID"] = Label35.Text;
dtCurrentTable.Rows[0]["Vid"] = Label33.Text;
dtCurrentTable.Rows[0]["TarifaID"] = Label14.Text;
dtCurrentTable.AcceptChanges();
GridView2.DataSource = dtCurrentTable;
GridView2.DataBind();
RemoveDuplicates(dt);
}
答案 0 :(得分:0)
您可以使用EditItemTemplate来对应gridview中的每个模板字段。