Gridview edit textbox gönderme sorunu

justoverback

Hectopat
Katılım
28 Ekim 2018
Mesajlar
79
Yukarıdaki textboxtan alınan verileri aşağıdaki textboxa aktaracağım. Şimdiden teşekkürler
[CODE lang="aspnet" title="default.aspx"] <form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<strong>Edit Update Delete Operation in Gridview</strong></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="id" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" CellSpacing="2">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="LabelID" Text='<%# Bind("id") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>



<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="editBoxName" ReadOnly="true" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="City">
<EditItemTemplate>
<asp:TextBox ID="editBoxCity" ReadOnly="true" runat="server" Text='<%# Bind("city") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("city") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>



<asp:TemplateField HeaderText="Miktar" Visible="false">
<EditItemTemplate>
<asp:TextBox ID="editBoxMik" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Fiyat" Visible="false">
<EditItemTemplate>
<asp:TextBox ID="editBoxFiy" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Tutar" Visible="false">
<EditItemTemplate>
<asp:TextBox ID="editBoxTut" ReadOnly="true" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>


</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<div>
<asp:Label ID="sipID" runat="server" Text="ıd">
</asp:Label><asp:TextBox ReadOnly="true" ID="txtsipID" runat="server"></asp:TextBox>
<br />
<asp:Label ID="sipName" runat="server" Text="ad">
</asp:Label><asp:TextBox ReadOnly="true" ID="txtsipName" runat="server"></asp:TextBox>
<br />

<asp:Label ID="sipAdet" runat="server" Text="adet">
</asp:Label><asp:TextBox ReadOnly="true" ID="txtsipAdet" runat="server"></asp:TextBox>
<br />

<asp:Label ID="sipFiyat" runat="server" Text="fıyat">
</asp:Label><asp:TextBox ReadOnly="true" ID="txtsipFiyat" runat="server"></asp:TextBox>
<br />

<asp:Label ID="sipTutar" runat="server" Text="tutar">
</asp:Label><asp:TextBox ReadOnly="true" ID="txtsipTutar" runat="server"></asp:TextBox>
</div>
</div>
</form>[/CODE]


[CODE lang="csharp" title="default.aspx.cs"] protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
refreshdata();
}
}

public void refreshdata()
{
SqlConnection con = new SqlConnection("Data Source=BERKAY;Initial Catalog=database;Integrated Security=True;");
SqlCommand cmd = new SqlCommand("select * from tbl_data", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();


}

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=BERKAY;Initial Catalog=database;Integrated Security=True;");
int id = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("delete from tbl_data where id =@id", con);
cmd.Parameters.AddWithValue("id", id);
int i = cmd.ExecuteNonQuery();
con.Close();
refreshdata();
}

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.Columns[2].Visible = true;
GridView1.Columns[3].Visible = true;
GridView1.Columns[4].Visible = true;
GridView1.Columns[5].Visible = true;
refreshdata();

}

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
refreshdata();
}


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label txtid = GridView1.Rows[e.RowIndex].FindControl("LabelID") as Label;
txtsipID.Text = txtid.Text;

TextBox txtname = GridView1.Rows[e.RowIndex].FindControl("editBoxName") as TextBox;
txtsipName.Text = txtname.Text;


//ÇALIŞMAYAN KISIM
TextBox txtmik = GridView1.Rows[e.RowIndex].FindControl("editBoxMik") as TextBox;
txtsipAdet.Text = txtmik.Text;

TextBox txtfiyat = GridView1.Rows[e.RowIndex].FindControl("editBoxFiy") as TextBox;
txtsipFiyat.Text = txtfiyat.Text;

TextBox txttutar = GridView1.Rows[e.RowIndex].FindControl("editBoxTut") as TextBox;
txtsipTutar.Text = txttutar.Text;



}[/CODE]
 

Dosya Ekleri

  • testt.png
    testt.png
    17,6 KB · Görüntüleme: 50
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Bu konuyu görüntüleyen kullanıcılar

Technopat Haberler

Yeni konular

Geri
Yukarı