I store all data in MySQL and display it's some colums in gridview. Gridview's delete button works fine. I would like to edit datas so created HyperLink. it navigates another url and gets values from MySQL DB and sets textboxes, textareas. Everything is fine until this time but I try to edit values in new page it sets old values in DB. How i can solve this problem?
This my Main Page which has gridview and delete button, hyperlink KayitGoruntule.aspx;
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="KayitGoruntule.aspx.cs" Inherits="gop.KayitGoruntule" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.string {
text-align: left;
}
</style>
</head>
<body>
<center><asp:Image ID="Banner" runat="server" ImageUrl="images/logo.png" Height="88px" Width="509px"></asp:Image></center>
<form id="form1" runat="server">
<br />
<div>
<asp:GridView ID="gvMysqlData" runat="server" CssClass="string"
SelectedIndex="0" DataKeyNames="id"
ShowHeaderWhenEmpty="True" OnRowDeleting="gvMysqlData_RowDeleting" Height="95px" Width="492px" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Width="15%">
<ItemTemplate>
<asp:HyperLink ID="hpr1" runat="server" NavigateUrl='<%# string.Format("KayitAyrinti.aspx?id={0}",Eval("id")) %>'>
<img src="images/edit.png" />
</asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
</form>
</body>
</html>
Navigated Url's page KayitAyrinti.aspx;
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="KayitAyrinti.aspx.cs" Inherits="gop.KayitAyrinti" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style2 {
height: 23px;
width: 217px;
}
.auto-style1 {
height: 23px;
width: 271px;
}
.degistir-button {
background:#7ab752;
margin:1px auto 0px;
text-align:right;
color:#FFF;
/*border:none;
border-top-left-radius:4px;
border-bottom-left-radius:4px;*/
-webkit-transition:background 0.5s;
}
.degistir-button:hover {
background:#DC3F42 #81c356;
}
.kaydet-button {
background:#7ab752;
margin:auto;
margin-right:4px;
margin-left:60px;
text-align:right;
color:#FFF;
/* border:none;
border-top-left-radius:40px;
border-bottom-left-radius:40px;
*/
-webkit-transition:background 0.5s;
}
.kaydet-button:hover {
background:#DC3F42 #81c356;
}
</style>
</head>
<body>
<center><asp:Image ID="Banner" runat="server" ImageUrl="images/logo.png" Height="88px" Width="509px"></asp:Image></center>
<form id="register" runat="server">
<br />
<div>
<table align="center">
<tr>
<td class="auto-style1" >
<asp:Label ID="lbl_ayrintiYetkiliAdSoyad" runat="server" Text="Yetkili Adı Soyad :" Font-Bold="True" Font-Names="Book Antiqua" ></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiYetkiliAdSoyad_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ayrintiGorusmeYapilanOkul" runat="server" Text="Görüşme Yapılan Okul :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:RadioButtonList ID="RadioButtonList_ayrintiGorusmeYapilanOkul" runat="server" Width="174px">
<asp:ListItem>Seyrantepe Şube 1</asp:ListItem>
<asp:ListItem>Seyrantepe Şube 2</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ayrintiveliAdSoyad" runat="server" Text="Veli Adı Soyadı :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiVeliAdiSoyadi_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_veliTel" runat="server" Text="Veli Telefon Numarası :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiVeliTel_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ikametAdres" runat="server" Text="İkamet Adresi :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<textarea id="ayrintiIkametAdres_txt" rows="5" cols="26" runat="server"></textarea>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ogrenciAdSoyad" runat="server" Text="Öğrenci Adı Soyadı :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiOgrenciAdSoyad_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ogrenciTel" runat="server" Text="Öğrenci Telefon Numarası :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiOgrenciTel_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ilgilendigiBolum" runat="server" Text="İlgilendiği Bölüm :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:RadioButtonList ID="RadioButtonList_ayrintiIlgilendigiBolum" runat="server" Width="174px">
<asp:ListItem>Hemşire Yardımcılığı</asp:ListItem>
<asp:ListItem>Sağlık Bakım Teknisyenliği</asp:ListItem>
<asp:ListItem>Anadolu Lisesi</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_verilenFiyat" runat="server" Text="Verilen Fiyat :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiVerilenFiyat_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_gorusmeSonucu" runat="server" Text="Görüşme Sonucu :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiGorusmeSonucu_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_gorusmeNotlari" runat="server" Text="Görüşme Notları :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<textarea id="ayrintiGorusmeNotlari_txt" rows="5" cols="26" runat="server"></textarea>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label1" runat="server" Text="" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:button id="degistir" runat="server" text="Değiştir" class="degistir-button" OnClick="degistir_Click"/>
<asp:Button ID="kaydet" runat="server" Text="Kaydet" CssClass="kaydet-button" OnClick="kaydet_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
This class is which shows values and try to update with degistir_Click,
KayitAyrinti.aspx.cs;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace gop
{
public partial class KayitAyrinti : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["kullanici"] != null)
{
Response.Write("Hoşgeldiniz..." + Session["kullanici"]);
Response.Redirect("KayitAyrinti.aspx");
}
else
{
// Response.Write("Giriş Yapınız.");
}
string connectionString = "xxx;Database=xxx;Uid=xxxx;Pwd=xxx;";
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
string[] keys = Request.QueryString.GetValues("id");
String id = keys[0];
MySqlCommand cmd = new MySqlCommand("select id, yetkiliAdSoyad,gorusmeYapilanOkul,veliAdSoyad, veliTel, ikametAdres, ogrenciAdSoyad, ogrenciTel, ilgilendigiBolum,verilenFiyat,gorusmeSonucu,gorusmeNotlari from Kayitlar where id=" + id + "", cn);
try
{
cn.Open();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ayrintiYetkiliAdSoyad_txt.Text = (reader["yetkiliAdSoyad"].ToString());
RadioButtonList_ayrintiIlgilendigiBolum.SelectedValue = (reader["gorusmeYapilanOkul"].ToString());
ayrintiVeliAdiSoyadi_txt.Text = (reader["veliAdSoyad"].ToString());
ayrintiVeliTel_txt.Text = (reader["veliTel"].ToString());
ayrintiIkametAdres_txt.InnerText = (reader["ikametAdres"].ToString());
ayrintiOgrenciAdSoyad_txt.Text= (reader["ogrenciAdSoyad"].ToString());
ayrintiOgrenciTel_txt.Text = (reader["ogrenciTel"].ToString());
RadioButtonList_ayrintiIlgilendigiBolum.SelectedValue= (reader["ilgilendigiBolum"].ToString());
ayrintiVerilenFiyat_txt.Text= (reader["verilenFiyat"].ToString());
ayrintiGorusmeSonucu_txt.Text= (reader["gorusmeSonucu"].ToString());
ayrintiGorusmeNotlari_txt.InnerText = (reader["gorusmeNotlari"].ToString());
}
}
}
catch (Exception ex)
{
}
}
}
protected void degistir_Click(object sender, EventArgs e)
{
string connectionString = "Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx;";
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
string[] keys = Request.QueryString.GetValues("id");
String id = keys[0];
cn.Open();
MySqlCommand komut = new MySqlCommand("UPDATE Kayitlar SET yetkiliAdSoyad=#ayrintiYetkiliAdSoyad, gorusmeYapilanOkul = #ayrintiGorusmeYapilanOkul,"+
" veliAdSoyad = #ayrintiVeliAdSoyad ,veliTel = #ayrintiVeliTel,ikametAdres = #ayrintiIkametAdres ,ogrenciAdSoyad = #ayrintiOgrenciAdSoyad, " +
"ogrenciTel=#ayrintiOgrenciTel,ilgilendigiBolum = #ayrintiIlgilendigiBolum,verilenFiyat=#ayrintiVerilenFiyat,gorusmeSonucu=#ayrintiGorusmeSonucu,gorusmeNotlari=#ayrintiGorusmeNotlari", cn);
komut.Parameters.AddWithValue("#ayrintiYetkiliAdSoyad", ayrintiYetkiliAdSoyad_txt.Text);
komut.Parameters.AddWithValue("#ayrintiGorusmeYapilanOkul", RadioButtonList_ayrintiGorusmeYapilanOkul.SelectedValue);
komut.Parameters.AddWithValue("#ayrintiVeliAdSoyad", ayrintiVeliAdiSoyadi_txt.Text);
komut.Parameters.AddWithValue("#ayrintiVeliTel", ayrintiVeliTel_txt.Text);
komut.Parameters.AddWithValue("#ayrintiIkametAdres", ayrintiIkametAdres_txt.InnerText);
komut.Parameters.AddWithValue("#ayrintiOgrenciAdSoyad", ayrintiOgrenciAdSoyad_txt.Text);
komut.Parameters.AddWithValue("#ayrintiOgrenciTel", ayrintiOgrenciTel_txt.Text);
komut.Parameters.AddWithValue("#ayrintiIlgilendigiBolum", RadioButtonList_ayrintiIlgilendigiBolum.SelectedValue);
komut.Parameters.AddWithValue("#ayrintiVerilenFiyat", ayrintiVerilenFiyat_txt.Text);
komut.Parameters.AddWithValue("#ayrintiGorusmeSonucu", ayrintiGorusmeSonucu_txt.Text);
komut.Parameters.AddWithValue("#ayrintiGorusmeNotlari", ayrintiGorusmeNotlari_txt.InnerText);
komut.ExecuteNonQuery();
Response.Redirect("KayitGoruntule.aspx");
komut.Dispose();
}
}
protected void kaydet_Click(object sender, EventArgs e)
{
}
}
}
The textboxes on your form are being populated with their database defaults in the Page_Load event. This is fine the first time through; however, when you click your 'degistir' button, a "postback" occurs, and Page_Load fires again and repopulates those defaults, losing whatever changes were submitted. Keep in mind that Page_Load fires before any control click events.
To fix this, you need to check for IsPostback in Page_Load to prevent your loader from firing on the update. If IsPostback is true, inhibit the load of the defaults from your database. This, in turn, should allow the update to occur with the updated data provided on your form. Something along these lines:
// code snipped...
if (Session["kullanici"] != null)
{
Response.Write("Hoşgeldiniz..." + Session["kullanici"]);
Response.Redirect("KayitAyrinti.aspx");
}
else
{
// Response.Write("Giriş Yapınız.");
}
if (!IsPostback) // <-- Add this check
{
string connectionString = "xxx;Database=xxx;Uid=xxxx;Pwd=xxx;";
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
string[] keys = Request.QueryString.GetValues("id");
/// rest of code snipped
Also, be sure to modify your UPDATE statement to include a WHERE clause that limits the UPDATE to only that record with the desired ID. As it is, ALL your records will be updated!
Related
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class UserAttendance : System.Web.UI.Page
{
SqlConnection vid = new SqlConnection("Data Source=DESKTOP-430E2O0\\SQLEXPRESS;Initial Catalog=mca;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
TextBox1.Visible = true;
String str = "select * from Student where (Course like '%' + #search + '%')";
String str1 = "select * from Student where (Semester like '%' + #search + '%')";
SqlCommand xp = new SqlCommand(str, vid);
SqlCommand xp1 = new SqlCommand(str1, vid);
xp.Parameters.Add("#search", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem.Text;
xp1.Parameters.Add("#search", SqlDbType.NVarChar).Value = DropDownList2.SelectedItem.Text;
vid.Open();
xp.ExecuteNonQuery();
xp1.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
da.SelectCommand = xp1;
DataSet ds = new DataSet();
da.Fill(ds, "Course");
da.Fill(ds, "Semester");
GridView1.DataSource = ds;
GridView1.DataBind();
vid.Close();
Button2.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
//I wish to use this button to save details to the database
}
}
<%# Page Title="" Language="C#" MasterPageFile="~/User.master" AutoEventWireup="true" CodeFile="UserAttendance.aspx.cs" Inherits="UserAttendance" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 179px;
}
.auto-style3 {
width: 6px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Course] FROM [Course]"></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Course" DataValueField="Course">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="Semester" DataValueField="Semester">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3" DataTextField="Subject" DataValueField="Subject">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" Width="49px" />
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="False"></asp:Calendar>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Semester] FROM [Semester]"></asp:SqlDataSource>
</td>
<td>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem>Present</asp:ListItem>
<asp:ListItem>Absent</asp:ListItem>
<asp:ListItem>Holiday</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Subject] FROM [Subject]"></asp:SqlDataSource>
</td>
<td style="text-align: justify">
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Save" Visible="False" Width="58px" />
</td>
<td class="auto-style3"> </td>
</tr>
</table>
</form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>
I have a textbox which contains date(out side the Gridview)
I have a dropdownlist in the gridview as a templatefield(Absent/Present)
I have a button called "save" outside of the grid view
When I press the save button the details should go to database and should be saved in a table Attendance.
Columns of Attendance Table
1.ID
2.Name
3.Course
4.Semester
5.Date
6.Status(Absent/Present)
I am making a exam web application in ASP.NET. I am using grid-view for showing question and the possible answers. I set size of grid view is 1 so it display only one question on a page-index. I am using radio button for multiple choice option.
When I select a radio button and going to next question or next page index of grid-view and come again previous question then I see that the radio button which I selected previously is not selected. What should I do for this?
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1"
GridLines="None" Height="380px"
onpageindexchanging="GridView1_PageIndexChanging"
onprerender="GridView1_PreRender" onrowcommand="GridView1_RowCommand"
OnRowDataBound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="1"
ShowHeader="False" style="margin-right: 0px; margin-bottom: 0px;"
Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style=" width:100%; height: 550px;">
<tr>
<td class="style6" colspan="2" colspan="3"
style="border-width: 1px; border-bottom-style: inset;">
<asp:Label ID="Label14" runat="server" Font-Size="Large" Text="Question No :-"></asp:Label>
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Size="Large"
Text='<%# Eval("id") %>'></asp:Label>
</td>
</tr>
<tr>
<td class="style4" colspan="2" colspan="2">
<asp:Label ID="Label15" runat="server" Font-Bold="True" Text="Question:-"
Font-Size="Large"></asp:Label>
<br /> <asp:Label ID="Label6" runat="server" Font-Bold="False"
Text='<%# Eval("Question") %>'></asp:Label>
</td>
</tr>
<tr>
<td class="style9" style=" padding-top:10px">
A:-<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
Font-Bold="False"
oncheckedchanged="RadioButton1_CheckedChanged" Text='<%# Eval("A") %>' />
<br />
</td>
<td class="style1" rowspan="4" style=" padding-top:10px">
<asp:Image ID="Image1" runat="server" BorderStyle="None" Height="149px"
ImageUrl='<%# Eval("image") %>' Width="449px" />
</td>
</tr>
<tr>
<td class="style9">
B:-<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
Font-Bold="False"
oncheckedchanged="RadioButton2_CheckedChanged" Text='<%# Eval("B") %>' />
<br />
</td>
</tr>
<tr>
<td class="style9">
C:-<asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="True"
Font-Bold="False"
oncheckedchanged="RadioButton3_CheckedChanged" Text='<%# Eval("C") %>' />
<br />
</td>
</tr>
<tr>
<td class="style9">
D:-<asp:RadioButton ID="RadioButton4" runat="server" AutoPostBack="True"
Font-Bold="False"
oncheckedchanged="RadioButton4_CheckedChanged" Text='<%# Eval("D") %>' />
<br />
</td>
</tr>
<tr>
<td colspan="2">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<asp:Button ID="Button12" runat="server" BackColor="#006699" BorderStyle="None"
Font-Bold="True" Font-Size="Large" ForeColor="White" Height="34px"
Text="Next>>>" Width="230px" />
<asp:Button ID="Button2" runat="server" BackColor="#006699" BorderStyle="None"
CommandArgument='<%# Eval("id") %>' CommandName="Next" Font-Bold="True"
Font-Size="Large" ForeColor="White" Height="34px" Text="Mark for Review & Next"
Width="229px" />
<asp:Button ID="Button1" runat="server" BackColor="#006699" BorderStyle="None"
CommandArgument='<%# Eval("id") %>' CommandName="Save" Font-Bold="True"
Font-Size="Large" ForeColor="White" Height="34px" OnClick="Button1_Click"
Text="Save and Next" Width="230px" />
</td>
</tr>
</table>
</ItemTemplate>
<AlternatingItemTemplate>
<table style=" width:100%; height: 550px;">
<tr>
<td class="style9" colspan="2">
Q<span ID="GridView1_ctl02_Label14" style="font-size:Large;">0</span> .
<span ID="GridView1_ctl02_Label6" style="font-size:Large;font-weight:bold;">abc</span>
</td>
</tr>
<tr>
<td class="style9">
C:-<span style="font-size:Large;font-weight:normal;"><input
ID="GridView1_ctl02_RadioButton3" name="GridView1$ctl02$RadioButton3"
onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton3\',\'\')', 0)"
type="radio" value="RadioButton3" /><label
for="GridView1_ctl02_RadioButton3">abc</label></span>
<br />
</td>
<td class="style6" colspan="2"
style=" border-width: 1px; border-bottom-style: inset;">
A:-<span style="font-size:Large;font-weight:bold;"
ID="GridView1_ctl02_Label4"><input
ID="GridView1_ctl02_RadioButton1" name="GridView1$ctl02$RadioButton1"
onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton1\',\'\')', 0)"
type="radio" value="RadioButton1" /><label
for="GridView1_ctl02_RadioButton1">abc</label></span>
<br />
</td>
<td class="style1" rowspan="4" style=" padding-top:10px">
<img ID="GridView1_ctl02_Image1" Src=""
style="border-style:None;height:98px;width:231px;border-width:0px;" />
</td>
</tr>
<tr>
<td class="style4" colspan="2">
B:-<span style="font-weight:bold;" ID="GridView1_ctl02_Label15"><input
ID="GridView1_ctl02_RadioButton2" name="GridView1$ctl02$RadioButton2"
onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton2\',\'\')', 0)"
type="radio" value="RadioButton2" /><label
for="GridView1_ctl02_RadioButton2">abc</label></span>
<br />
</td>
</tr>
<tr>
</tr>
<tr>
<td class="style9">
D:-<span style="font-size:Large;font-weight:normal;"><input
ID="GridView1_ctl02_RadioButton3" name="GridView1$ctl02$RadioButton3"
onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton3\',\'\')', 0)"
type="radio" value="RadioButton3" /><label
for="GridView1_ctl02_RadioButton4">abc</label></span>
<br />
</td>
</tr>
<tr>
<td colspan="2">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<input ID="GridView1_ctl02_Button12" name="GridView1$ctl02$Button12"
style="color:White;background-color:#006699;border-style:None;font-size:Large;font-weight:bold;height:34px;width:230px;"
type="submit" value="<<<Prv" /> <input
ID="GridView1_ctl02_Button2" name="GridView1$ctl02$Button2"
style="color:White;background-color:#006699;border-style:None;font-size:Large;font-weight:bold;height:34px;width:229px;"
type="submit" value="Mark and Next" />
<input ID="GridView1_ctl02_Button1" name="GridView1$ctl02$Button1"
style="color:White;background-color:#006699;border-style:None;font-size:Large;font-weight:bold;height:34px;width:230px;"
type="submit" value="Save and Next" />
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="White" BorderColor="White" ForeColor="White" />
</asp:GridView>
Save Answer in View-state using code
if (e.CommandName == "Save")
{
foreach (GridViewRow row in GridView1.Rows)
{
if (((RadioButton)row.FindControl("RadioButton1")).Checked)
{
Label12.Text = "A";
}
if (((RadioButton)row.FindControl("RadioButton2")).Checked)
{
Label12.Text = "B";
}
if (((RadioButton)row.FindControl("RadioButton3")).Checked)
{
Label12.Text = "C";
}
if (((RadioButton)row.FindControl("RadioButton4")).Checked)
{
Label12.Text = "D";
}
string m = Convert.ToString(e.CommandArgument);
ViewState[m] = Label12.Text;
}
Run a for Loop in Row Data Bound event of GridView1
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string id = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "id"));
int i, j;
for (i = 1; i <= 65; i++)
{
j = i + 100;
string k = i.ToString();
string l = j.ToString();
if (ViewState[l] != null)
{
if (id == k)
{
if (ViewState[l].ToString() == "A")
{
(e.Row.Cells[0].FindControl("RadioButton1") as RadioButton).Checked = true;
}
if (ViewState[l].ToString() == "B")
{
(e.Row.Cells[0].FindControl("RadioButton2") as RadioButton).Checked = true;
}
if (ViewState[l].ToString() == "C")
{
(e.Row.Cells[0].FindControl("RadioButton3") as RadioButton).Checked = true;
}
if (ViewState[l].ToString() == "D")
{
(e.Row.Cells[0].FindControl("RadioButton4") as RadioButton).Checked = true;
}
}
}
}
}
}
Solve !!!!!
I'm getting this error while binding data to data list
too many characters in character literal asp.net
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="android.aspx.cs" Inherits="finalproject.android" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
.style1
{
width:900px;
}
.style2
{
width:633px;
text-align:left;
}
.style4
{
width:185px;
text-align:center;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:DataList ID="DataList1" runat="server" DataKeyField="modelid"
style="text-align: center; color: #333333;" RepeatColumns="3"
Width="283px" DataSourceID="SqlDataSource2" CellPadding="3"
BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
CellSpacing="1" >
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
<ItemTemplate>
<br />
<div align="left"></div>
<table cellspacing="1" class="style4" style="border:1px ridge #9900FF">
<tr>
<td style="border-bottom-style:ridge; border-width: 1px; border-color: #000000">
<asp:Label ID="Label1" runat="server" Text="<%# Eval('brand') %>"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" Height="252px"
ImageUrl="<%# Image %>" style="margin-left: 0px" />
</td>
</tr>
<tr>
<td>
ModelID<asp:Label ID="Label2" runat="server" Text="<%# Eval('modelid') %>"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
CommandArgument="<%# Bind('ModelID') %>" Text="Add to Cart" Width="100%" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px" />
</td>
</tr>
</table>
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:VISHConnectionString2 %>"
SelectCommand="SELECT [Image], [modelid], [brand] FROM [adddetails]">
</asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table align="left" class="style2">
<tr>
<td>
<asp:Label ID="Label3" runat="server" style="color: #333333"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
I'm getting this error while binding data to data list
too many characters in character literal asp.net
"too many characters in character literal" is caused by having a char-literal with too many characters in it.
You have probably mixed up the '-character and the "-character.
The error probably lies in your "android.aspx.cs"-file rather than the .aspx-file that you have provided.
Could you provide the code for that as well?
Well, your problems are right here:
<%# Bind('ModelID') %>
Replace your single-quotes with double-quotes and you will be golden!
<%# Bind("ModelID") %>
Same goes for all your Evals/Binds
Also see these questions:
Why I'm getting CS1012: "Too many characters in character literal" and CS0019?
Too many characters in character literal?
I think the origin of the error is:
Eval('brand')
It tries to convert brand to a character and fails with that error.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="android.aspx.cs" Inherits="finalproject.android" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
.style1
{
width:900px;
}
.style2
{
width:633px;
text-align:left;
}
.style4
{
width:185px;
text-align:center;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:DataList ID="DataList1" runat="server" DataKeyField="modelid"
style="text-align: center; color: #333333;" RepeatColumns="3"
Width="283px" DataSourceID="SqlDataSource2" CellPadding="3"
BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
CellSpacing="1" >
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
<ItemTemplate>
<br />
<div align="left"></div>
<table cellspacing="1" class="style4" style="border:1px ridge #9900FF">
<tr>
<td style="border-bottom-style:ridge; border-width: 1px; border-color: #000000">
<asp:Label ID="Label1" runat="server" Text="<%# Eval('brand') %>"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" Height="252px"
ImageUrl="<%# Image %>" style="margin-left: 0px" />
</td>
</tr>
<tr>
<td>
ModelID<asp:Label ID="Label2" runat="server" Text="<%# Eval('modelid') %>"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
CommandArgument="<%# Bind('ModelID') %>" Text="Add to Cart" Width="100%" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px" />
</td>
</tr>
</table>
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:VISHConnectionString2 %>"
SelectCommand="SELECT [Image], [modelid], [brand] FROM [adddetails]">
</asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table align="left" class="style2">
<tr>
<td>
<asp:Label ID="Label3" runat="server" style="color: #333333"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
I have hidden field in gridview. I do not get the value in code behind. It works fine without MasterPage and Ajax, can you help me to get a value in code behind.
Thanks
protected void empgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "UpdateEmployee")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = empgrid.Rows[index];
Session["Employee"] = ((HiddenField)empgrid.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("EmployeeID")).Value;
Response.Redirect("UpdateEmployee.aspx");
}
}
<%# Page EnableEventValidation = "false" Title="" MasterPageFile="~/EmploymentWeb.Master" Language="C#" AutoEventWireup="true" CodeBehind="employeeborowes.aspx.cs" Inherits="Employment_Site.employeeborowes" %>
<asp:Content ID="Content1" ContentPlaceHolderID="AllContent" runat="server">
<table style="width: 100%">
<tr>
<td style="width: 105px">
<asp:Label ID="Label1" runat="server" Text="Employee Name"></asp:Label>
</td>
<td style="width: 178px">
<asp:TextBox ID="empname" runat="server" Width="165px"></asp:TextBox>
</td>
<td class="style2" style="width: 61px">
<asp:Button ID="btnsearch" runat="server" Text="Search" Width="70px"
onclick="btnsearch_Click" />
</td>
<td class="style2" style="width: 72px">
<asp:Button ID="btnclear" runat="server" onclick="btnclear_Click" Text="Clear"
Width="70px" />
</td>
<td style="width: 144px">
</td>
</tr>
<tr>
<td style="width: 105px">
</td>
<td colspan="4">
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional" >
<ContentTemplate>
<asp:GridView ID="empgrid" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Width="303px"
onrowcommand="empgrid_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:HiddenField ID="EmployeeID" runat="server" Value='<%# Eval("EmployeeID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnupdate" runat="server" Text="Update"
CommandName="UpdateEmployee" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width: 105px">
</td>
<td style="width: 178px">
</td>
<td class="style2" style="width: 61px">
</td>
<td class="style2" style="width: 72px">
</td>
<td style="width: 144px">
</td>
</tr>
<tr>
<td style="width: 105px">
</td>
<td style="width: 178px">
</td>
<td class="style2" style="width: 61px">
</td>
<td class="style2" style="width: 72px">
</td>
<td style="width: 144px">
</td>
</tr>
</table>
</asp:Content>
Try this
GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
HiddenField empID = (HiddenField)row.FindControl("EmployeeID");
Session["Employee"] = empID.Value;
Try This:
Use Response.Redirect("UpdateEmployee.aspx",false);
instead of Response.Redirect("UpdateEmployee.aspx");
This is because of the way Redirect and session variables work.
When you create a new session an volatile cookie is set on the client that contains the session token. On all subsequent requests, and as long as the server session and the client cookie have not expired, ASP.NET can look at this cookie and find the right session.
what Redirect does is to send a special header to the client so that it asks the server for a different page than the one it was waiting for.
Hope this helps!!
I try to write data grid in aspx. In my database there is a column which name is 'PROJECT_NAME'. I want these columns in my data grid, then I add second column (editbox) to add values every each of project. This is all in grid view, and I add button in form. When I press the button how can I understand which columns value belong which project?
I mean, for example
Row value : A project 2 Column value : 50
Row value : B project 2 Column value : 60
Row value : C project 2 Column value : 70
I want to know when I press button 1. project value 50 how can ı understand this?
This is my aspx code :
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 78px;
}
.style2
{
width: 426px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 561px">
<table style="width: 100%; height: 556px;">
<tr>
<td>
</td>
<td>
<table style="width:100%;">
<tr>
<td class="style1">
Ay</td>
<td>
<asp:TextBox ID="ay" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
Yıl</td>
<td>
<asp:TextBox ID="yil" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:GridView ID="portföy" runat="server"
CellPadding="3" GridLines="Horizontal"
AutoGenerateColumns="False"
DataKeyNames="PRJ_PROJECT_NAME" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" Font-Bold="False" Font-Names="Verdana"
Font-Overline="False" Font-Size="Smaller" Width="1000px"
>
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:TemplateField HeaderText="PRJ_PROJECT_NAME" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblProjeTT" runat="server" Text='<%# Bind("PRJ_PROJECT_NAME") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Miktar (a/g)" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox runat="server" id="txtField1" Text='<%# Bind("TAMAMLANMA_YUZDESI") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" id="txtField1" Text='<%# Bind("TAMAMLANMA_YUZDESI") %>'/>
</EditItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ShowHeader="False" HeaderStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<EditRowStyle BackColor="#FFFFA8" ForeColor="Black" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
<table style="width:100%;">
<tr>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
Width="149px" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
csOra cOra;
string oraTns = ConfigurationManager.AppSettings["TNS"];
string oraUserName = ConfigurationManager.AppSettings["OraUserName"];
string oraPassword = ConfigurationManager.AppSettings["OraPassword"];
protected void Page_Load(object sender, EventArgs e)
{
cOra = new csOra(oraTns, oraUserName, oraPassword);
if (cOra.OraCnn.State != ConnectionState.Open)
{
MessageBox.Show("Oracle ile bağlantı kurulamadı...");
return;
}
try
{
if (!IsPostBack)
{
setGrid();
}
}
catch (OleDbException ex)
{
Response.Write(#"Oracle Error:" + ex.Message);
return;
}
catch (Exception ex)
{
Response.Write(#"Error:" + ex.Message);
return;
}
}
void setGrid()
{
string sSQL = #"SELECT PRJ_PROJECT_NAME,TAMAMLANMA_YUZDESI
FROM PPIGANTT.KOKTEYL_TABLE_3
WHERE PRJ_PROJECT_NAME like '%d%'
ORDER BY Request_id";
try
{
OleDbDataAdapter oDa = new OleDbDataAdapter(sSQL, cOra.OraCnn);
DataTable portföy_ = new DataTable("KOKTEYL_TABLE_3");
oDa.Fill(portföy_);
if (portföy_.Rows.Count > 0)
{
portföy.DataSource = portföy_;
portföy.DataBind();
}
else
{
portföy_.Rows.Add(portföy_.NewRow());
portföy.DataSource = portföy_;
portföy.DataBind();
int TotalColumns = portföy.Rows[0].Cells.Count;
portföy.Rows[0].Cells.Clear();
portföy.Rows[0].Cells.Add(new TableCell());
portföy.Rows[0].Cells[0].ColumnSpan = TotalColumns;
portföy.Rows[0].Cells[0].Text = "No Record Found";
}
}
catch (OleDbException ex)
{
Response.Write(#"Oracle Error:" + ex.Message);
return;
}
catch (Exception ex)
{
Response.Write(#"Error:" + ex.Message);
return;
}
}
void UpdatePortföy(string Portföy, int bütçe )
{
string sSQL = #"BEGIN UPDATE PPIGANTT.KOKTEYL_TABLE_3
SET TAMAMLANMA_YUZDESI = " + bütçe + #"WHERE PRJ_PROJECT_NAME ='"
+ Portföy + #"' ; COMMIT; END;";
string sErr = "";
try
{
cOra.ExecNonQuery(sSQL, out sErr);
}
//setGrid();
catch (OleDbException ex)
{
Response.Write(#"Oracle Error:" + ex.Message);
return;
}
catch (Exception ex)
{
Response.Write(#"Error:" + ex.Message);
return;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
/* what can I write here to understand whic column value ?*/
}
}
Thanks.
Inside of Button1_Click you need need to loop through all the rows in the GridView and do a FindControl on each row to get the label and textbox. From that you can determine what the PRJ_PROJECT_NAME and values in the textbox are.
Here is an example:
Default.aspx
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblLabel" runat="server" Text='<%# Bind("Number") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtData" runat="server" Text='<%# Bind("Value") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Create some fake data and bind it to the gridview
var data = new List<TheData>();
foreach(var num in Enumerable.Range(1, 4))
{
var newData = new TheData();
newData.Number = num.ToString();
newData.Value = num;
data.Add(newData);
}
gvData.DataSource = data;
gvData.DataBind();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
for (var index = 0; index < gvData.Rows.Count; ++index)
{
var row = gvData.Rows[index];
var lblLabel = row.FindControl("lblLabel") as Label;
var txtData = row.FindControl("txtData") as TextBox;
//Here is where the values are grabbed, at this point you can do what you need to.
var number = lblLabel.Text;
var value = txtData.Text;
}
}
one solution I have used before takes advantage of the CommandArgument attribute of the button. You can set the CommandArgument='<% Eval("ColumnValueYouWant") %>' and each button will get the value for the column in it's row. Then, in the click event you can parse the object sender back into a Button and access the CommandArgument value.