Hidden Field in Gridview - c#

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!!

Related

radio button in gridview template field

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 !!!!!

Update MySQL using HyperLink ASP.NET

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!

Can't display male/female for gender in gridview

I have a data field "Gender" (sql data type - bit).
I have created bound the data with if condition to check true-> male otherwise -> female. But it still does not display.
Here is the aspx and code behind code:The gridview shows true/false instead of male/female:
<%# Page Title="Add User" Language="C#" AutoEventWireup="true" CodeFile="adduser.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!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 id="Head1" runat="server">
<title></title>
<link href="style.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript">
function confirmDelete() {
return confirm("Do you want to delete this record?");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="toolkit1" runat="server">
</ajax:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" align="center" cellpadding="2" cellspacing="2" class="maindiv">
<tr><!--Hidden field for EmployeeID reference-->
<td colspan="2"><asp:HiddenField ID="txtHiddenEmpID" Value="0" runat="server" /></td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="name" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmpName" runat="server" CssClass="box"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ID="RequiredFieldValidator1" ErrorMessage="Name is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="txtEmpName"
CssClass="error_msg"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="NameValidator" runat="server" ErrorMessage="Name can not contain numeric or special characters."
ControlToValidate="txtEmpName" ValidationExpression="^[A-Za-z ]*$" CssClass="error_msg"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label1" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="addressBox" runat="server" CssClass="box"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ID="AddressValidator" ErrorMessage="Address is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="addressBox"
CssClass="error_msg"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label2" runat="server" Text="DOB"></asp:Label>
</td>
<td>
<asp:TextBox ID="dobBox" runat="server" CssClass="dob_cal box" ReadOnly="false" ></asp:TextBox>
<ajax:CalendarExtender ID="CalenderExtender1" TargetControlID="dobBox" Format="dd/MM/yyyy"
runat="server">
</ajax:CalendarExtender>
<asp:RequiredFieldValidator Display="None" ID="dobValidator" ErrorMessage="DOB is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="dobBox"
CssClass="error_msg"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label3" runat="server" Text="Salary"></asp:Label>
</td>
<td>
<asp:TextBox ID="salaryBox" runat="server" CssClass="box" MaxLength="8" ></asp:TextBox>
<asp:RequiredFieldValidator ID="salaryValidate" runat="server" ControlToValidate="salaryBox"
ErrorMessage="Salary is required!" Display="None" CssClass="error_msg" SetFocusOnError="true"
EnableClientScript="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="SalaryValidator" runat="server" ErrorMessage="Salary can contain only numeric values."
Display="None" ControlToValidate="salaryBox" ValidationExpression="^[0-9]*$"
CssClass="error_msg"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="gender" runat="server" Text="Gender"></asp:Label>
</td>
<td>
<span>
<asp:RadioButton GroupName="gendergrp" ID="gendermale" runat="server" Text="Male"
Checked="true" /></span><span style="padding-left: 5px;">
<asp:RadioButton GroupName="gendergrp" ID="genderfemale" runat="server" Text="Female"
Checked="false" /></span>
</td>
</tr>
<tr>
<td>
<div style="float: right; margin-right: -70px;">
<asp:Button ID="Button1" runat="server" CssClass="btn" Text="Save" OnClick="Button1_Click" /></div>
</td>
<td>
<div style="float: left; margin-left: 70px;">
<asp:Button ID="CancelBtn" CausesValidation="false" runat="server" CssClass="btn"
Text="Cancel" OnClick="CancelBtn_Click" />
</div>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblError" runat="server" CssClass="error_msg"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="valSum" DisplayMode="BulletList" EnableClientScript="true"
HeaderText="Error!" runat="server" CssClass="error_msg" />
</td>
</tr>
</table>
<!--div for data display-->
<div class="data_display">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="EmployeeID" EmptyDataText="There are no data records to display."
GridLines="Horizontal" BackColor="#CCCCCC" BorderColor="White" Font-Bold="False"
Font-Names="Arial" Font-Size="Medium" ForeColor="#666666"
AllowPaging="True" PageSize="5" PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom"
onpageindexchanging="GridView1_PageIndexChanging"
>
<Columns>
<%-- <asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="EmpID" runat="server" Value='<%# Eval("EmployeeID") %>' />
</ItemTemplate>
</asp:TemplateField>
--%> <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
SortExpression="EmployeeID" Visible="true" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="EmployeeName" HeaderText="Name" SortExpression="EmployeeName"
ItemStyle-Width="130px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="130px" />
</asp:BoundField>
<asp:BoundField DataField="DateOfBirth" HeaderText="DoB" SortExpression="DateOfBirth"
DataFormatString="{0:dd-MM-yyyy}" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Salary" HeaderText="Salary"
SortExpression="Salary">
<ItemStyle HorizontalAlign="Center" Width="90px" />
</asp:BoundField>
<asp:BoundField DataField="Gender" HeaderText="Gender" ItemStyle-Width="90px"
ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="EditBtn" runat="server" Text="Select" CausesValidation="false" OnClick="EditBtn_Click" />
<asp:Button ID="DelBtn" runat="server" Text="Delete" CausesValidation="false" OnClick="DelBtn_Click" OnClientClick="confirmDelete()" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#ffffff" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Gray" Font-Bold="false" ForeColor="White" />
<PagerStyle BackColor="Gray" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<br />
<span style="font-family: Arial; font-size: small; color: Green; font-weight: bold;">
You are viewing page <%=GridView1.PageIndex + 1%> of <%=GridView1.PageCount%>
</span>
</div>
<div>
<asp:Label ID="lblMessage" runat="server"></asp:Label></div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
**code behind:**
#region GridView Functions
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "True")
{
e.Row.Cells[4].Text = "Male";
}
else
{
e.Row.Cells[4].Text = "Female";
}
}
}
#endregion
The gridview Gender column shows true/false instead of male/female.
Thanks!
You need a TemplateField for this. Assuming Male equates to True, this should work:
<asp:TemplateField HeaderText="Gender" SortExpression="Gender">
<ItemTemplate><%# (Boolean.Parse(Eval("Gender").ToString())) ? "Male" : "Female" %></ItemTemplate>
</asp:TemplateField>

child grid SelectionChanged event does not fire in DevExpress

I have 2 ASPxGridView controls
- gvPatient and
- gvOrder
gvOrder is placed inside detail row template of gvPatient.
the issue i am faciing is i have to get the values of rows of gvOrder(child) on focus row changed or selection changed. I have code for these events but these events do not fire on selection changed of rows and focus changed of child grid . Strange this- here these child grid events fire on gvPatient(parent) row selection and focus changed.
code:
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Main.master" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td>
</td>
</tr>
<tr>
<td style="height:300px;" valign="top">
<dx:ASPxGridView ID="gvPatient" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSourceMaster"
Width="100%" Font-Size="11px" KeyFieldName="PAT_NUMBER" >
<Columns>
<dx:GridViewDataTextColumn Caption="PAT_NUMBER" FieldName="PAT_NUMBER" Visible="false">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="" FieldName="PATIENT_ID" Visible="false">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Patient" FieldName="FULL_NAME" >
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="MRN" FieldName="MRN" >
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Nursing Unit" FieldName="NURSING_UNIT">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Room" FieldName="ROOM_BED" >
</dx:GridViewDataTextColumn>
</Columns>
<Templates>
<DetailRow>
<div style="padding:5px;">
<div>
<dx:ASPxGridView ID="gvOrder" runat="server" KeyFieldName="ORDER_KEY" DataSourceID="SqlDataSourceDetail"
Width="100%" AutoGenerateColumns="false"
nbeforeperformdataselect="gvOrder_BeforePerformDataSelect"
OnSelectionChanged="gvOrder_SelectionChanged"
onfocusedrowchanged="gvOrder_FocusedRowChanged"
ondetailrowexpandedchanged="gvOrder_DetailRowExpandedChanged">
<Columns>
<dx:GridViewDataTextColumn Caption="ORDER KEY" FieldName="ORDER_KEY" Visible="false">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="PAT_NUMBER" FieldName="PAT_NUMBER" Visible="false">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Rx Edit" FieldName="RX" >
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Reason Code" FieldName="REASON_CODE" >
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Note" FieldName="NOTE">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowFooter="True" />
<SettingsBehavior AllowFocusedRow="true" AllowSelectByRowClick="true" />
</dx:ASPxGridView>
</div>
<div style="padding-top:5px; padding-left:5px;">
<table cellpadding="2" cellspacing="2" border="0" width="100%">
<tr>
<td rowspan="3">
<dx:ASPxRoundPanel ID="ASPxRoundPanel2" runat="server" Width="500px" BackColor="White"
HeaderText="PLEASE FOLLOW FEDERAL AND STATE GUIDELINES TO ORDER THIS CONTROLLED SUBSTANCE" >
<PanelCollection>
<dx:PanelContent>
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td align="left">
<dx:ASPxLabel ID="ASPxLabel11" runat="server" Text="Start">
</dx:ASPxLabel>
<b><dx:ASPxLabel ID="ASPxLabel12" runat="server" Text="04-04-13" Font-Bold="true" >
</dx:ASPxLabel></b>
</td>
<td align="right">
<dx:ASPxLabel ID="ASPxLabel13" runat="server" Text="Active" Font-Bold="true" >
</dx:ASPxLabel>
</td>
</tr>
<tr>
<td colspan="2">
<dx:ASPxLabel ID="ASPxLabel14" runat="server" Text="Initial">
</dx:ASPxLabel>
<b><dx:ASPxLabel ID="ASPxLabel15" runat="server" Text="04-04-13" Font-Bold="true" >
</dx:ASPxLabel></b>
</td>
</tr>
<tr>
<td colspan="2">
<dx:ASPxLabel ID="ASPxLabel16" runat="server" Text="Time Stamp">
</dx:ASPxLabel>
<b><dx:ASPxLabel ID="ASPxLabel17" runat="server" Text="04-04-13 02:53" Font-Bold="true" >
</dx:ASPxLabel></b>
</td>
</tr>
<tr>
<td colspan="2">
<dx:ASPxLabel ID="ASPxLabel18" runat="server" Text="OXYCODONE HCL IR 5MG TABLET (OXYCODONE HCL IR 5MB TABLET)" ></dx:ASPxLabel>
<br /><dx:ASPxLabel ID="ASPxLabel19" runat="server" Text="ONE TAB(5 mg) by mouth every 4 hours as neded pain tele order by bhardwaj, rakesh" ></dx:ASPxLabel>
<br /><dx:ASPxLabel ID="ASPxLabel20" runat="server" Text="noted on 04-04-13 2:53pm by erma entena, md" ></dx:ASPxLabel>
</td>
</tr>
</table>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxRoundPanel>
</td>
<td>
<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="Action:"></dx:ASPxLabel>
</td>
<td>
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" ValueType="System.String" Width="300px" >
<Items>
<dx:ListEditItem Text="" />
<dx:ListEditItem Text="Continue" />
<dx:ListEditItem Text="Discontinue" />
<dx:ListEditItem Text="Substitute" />
<dx:ListEditItem Text="Wean/Taper" />
</Items>
</dx:ASPxComboBox>
</td>
</tr>
<tr>
<td>
<dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="Reason:"></dx:ASPxLabel>
</td>
<td>
<dx:ASPxComboBox ID="cbReason" runat="server" ValueType="System.String" Width="300px" >
<Items>
<dx:ListEditItem Text="" />
<dx:ListEditItem Text="Duplicate Drugs" />
<dx:ListEditItem Text="Ineffective drug therapy" />
<dx:ListEditItem Text="Non-compliance with drug therapy" />
<dx:ListEditItem Text="Significant side effects" />
<dx:ListEditItem Text="Significant drug interactions" />
<dx:ListEditItem Text="Behavioral Changes" />
<dx:ListEditItem Text="POLST/MOLST" />
<dx:ListEditItem Text="Refusing Medication" />
</Items>
</dx:ASPxComboBox>
</td>
</tr>
<tr>
<td>
<dx:ASPxLabel ID="ASPxLabel2" runat="server" Text="Comment:"></dx:ASPxLabel>
</td>
<td>
<dx:ASPxMemo ID="tbNote" runat="server" Height="70px" Width="300px" ></dx:ASPxMemo>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<dx:ASPxButton ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click"></dx:ASPxButton>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<dx:ASPxLabel ID="lblMsg" runat="server" Text="" ForeColor="Red"></dx:ASPxLabel>
</td>
</tr>
</table>
</div>
</div>
</DetailRow>
</Templates>
<SettingsDetail ShowDetailRow="true" AllowOnlyOneMasterRowExpanded="true" />
<SettingsBehavior AllowFocusedRow="true" AllowSelectByRowClick="true" ProcessSelectionChangedOnServer="True" />
</dx:ASPxGridView>
</td>
</tr>
You need to set properties SettingsBehavior.ProcessSelectionChangedOnServer and
SettingsBehavior.ProcessFocusedRowChangedOnServer to true.
From docs: "If the ProcessSelectionChangedOnServer property is set to false, the ASPxClientGridView.SelectionChanged event is handled on the client side without a postback to the server".

Gridview Calendar Extender get date

I have a GridView which allows users to enter data using a EmptyDataTemplate. There is a text box having a calendarextender. I want to get the date entered (format MM/dd/yyyy) and pass it to the database.
Please let me know how to do it.
My code:
<asp:GridView ID="GV_Rotl_Asgt" runat="server" EnableModelValidation="True"
BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" CellPadding="3" Font-Names="Arial"
Font-Size="8pt" GridLines="Vertical"
AllowSorting="True" EnableSortingAndPagingCallbacks="True" AutoGenerateColumns="False"
Width="1196px"
ShowFooter="True" OnRowCommand="GV_RowCommand" DataKeyNames="Emplid">
<FooterStyle BackColor="#CCCCCCC" ForeColor="Black" />
<PagerSettings PageButtonCount="1000" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Action" HeaderStyle-ForeColor="#00349C">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" CssClass="infotitle" /> <br />
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" CssClass="infotitle"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" CssClass="infotitle" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" CssClass="infotitle"/>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton runat="server" ID="Insert" Text="Insert" CommandName="InsertNew" CssClass="infotitle" />
<asp:LinkButton runat="server" ID="Cancel" Text="Cancel" CommandName="CancelNew" CssClass="infotitle" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<table id="NoDatatbl" width="100%" style="margin-right: 0px">
<tr>
<td class="ColumnHead" width="150px">
To Date</td>
<td class="ColumnHead" width="150px">
From Date</td>
<td class="ColumnHead" width="150px">
Rotational Assignment</td>
<td class="ColumnHead" width="150px">
Location</td>
<td class="ColumnHead" width="150px">
</td>
</tr>
</table>
<table id="NoDatatbl1" width="100%" style="margin-right: 0px">
<tr>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataToDt" format="MM/dd/yyyy"/>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="NodataToDt" format="MM/dd/yyyy"/>
</td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodatafrmDt" format="MM/dd/yyyy"/>
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="NodatafrmDt" format="MM/dd/yyyy"/>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="NodatafrmDt" ControlToCompare="NodataToDt" Operator="GreaterThanEqual"
Display="Dynamic" ErrorMessage="From Date should be greater than To Date"
Type="Date"></asp:CompareValidator>
<asp:ValidatorCalloutExtender ID="CompareValidator1_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="CompareValidator1">
</asp:ValidatorCalloutExtender>
</td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataRotl" /></td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataLoc" /></td>
<td class="ColumnHead" width="150px">
<asp:LinkButton runat="server" ID="LinkButton1" Text="Insert" CommandName="NoDataInsert" CssClass="infotitle" />
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
Basically, I want to fetch the values from the NodataToDt & NodatafrmDt textboxes in codebehind and pass the values to my stored procedure.
Thanks
In your code behind:
// Find the 2 text boxes within your GridView control
TextBox toDateTextBox = (TextBox)GV_Rotl_Asgt.FindControl("NodataToDt");
TextBox fromDateTextBox = (TextBox)GV_Rotl_Asgt.FindControl("NodatafrmDt");
// Grab the values out of those text boxes
string toDate = toDateTextBox.Text;
string fromDate = fromDateTextBox.Text;
From there, you can do whatever you need with those two string values.

Categories

Resources