display in textbox when checkbox is checked in gridview - c#

i have a checkbox in a gridview , i want to display row's data in textbox when i check o checkbox .this is my buttun's code :
protected void ButtonModifEnfant_Click(object sender, EventArgs e)
{
#region
try
{
int nbr_check = 0;
string myid = "";
for (int i = 0; i < gv_enfant.Rows.Count; i++)
{
CheckBox check = (CheckBox)gv_enfant.Rows[i].Cells[0].FindControl("CheckBoxenfant");
if (check.Checked)
{
myid = ((HiddenField)gv_enfant.Rows[i].Cells[0].FindControl("codeenfant")).Value;
//ButtonModifEnfant.Enabled = true;
//ButtonSuppEnfant.Enabled = true;
//myid = gv_enfant.Rows[i].Cells[0].Text;
//nbr_check++;
}
else
{
//ButtonModifEnfant.Enabled = false;
//ButtonSuppEnfant.Enabled = true;
}
}
if (nbr_check >= 1)
{
//ButtonModifEnfant.Enabled = true;
Response.Write("<script>alert ('Error!')</script>");
return;
}
else if (nbr_check == 1)
{
//ButtonModifEnfant.Enabled = true;
}
ModalPopupExtenderModifierEnfant.Show();
c.cmd = c.cn.CreateCommand();
c.cmd.CommandText = "select prenom , DateNaissance , Scolarise , Activite from Enfants where codeEnfants = " + myid;
if (c.cn.State == ConnectionState.Closed)
{
c.cn.Open();
}
SqlDataReader read = c.cmd.ExecuteReader();
if (read.HasRows)
{
read.Read();
TextBox_NPmodif.Text = read[0].ToString();
TextBox_DNmodif.Text = read[1].ToString();
TextBox_Scolarisemodif.Text = read[2].ToString();
TextBox_Activitemodif.Text = read[3].ToString();
}
read.Close();
//gv_enfant.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
if (c.cn.State == ConnectionState.Open)
{
c.cn.Close();
}
}
#endregion
}
and this is my checkbox code :
protected void CheckBoxEnfants_CheckedChanged(object sender, EventArgs e)
{
int chek = 0;
for (int i = 0; i < gv_enfant.Rows.Count; i++)
{
CheckBox chbox = (CheckBox)gv_enfant.Rows[i].Cells[0].FindControl("CheckBoxenfant");
if (chbox.Checked)
{
chek++;
}
}
if (chek != 1)
{
ButtonModifEnfant.Enabled = false;
ButtonSuppEnfant.Enabled = false;
}
else
{
ButtonModifEnfant.Enabled = true;
ButtonSuppEnfant.Enabled = true;
}
}
and for the html code of gridview :
<asp:GridView ID="gv_enfant" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1"
Width="533px">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxenfant" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBoxEnfants_CheckedChanged" />
<asp:HiddenField ID="codeenfant" runat="server" Value='<%# Eval("codeEnfants") %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="prenom" HeaderText="prenom" SortExpression="prenom" />
<asp:BoundField DataField="DateNaissance" HeaderText="Date Naissance" DataFormatString="{0:d}"
SortExpression="DateNaissance" />
<asp:BoundField DataField="Scolarise" HeaderText="Scolarise" SortExpression="Scolarise" />
<asp:BoundField DataField="Activite" HeaderText="Activite" SortExpression="Activite" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CVtechConnectionString10 %>"
SelectCommand="SELECT * FROM [Enfants] WHERE ([ppr] = #ppr)">
<SelectParameters>
<asp:SessionParameter Name="ppr" SessionField="code" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Thank you

This may help you.
if (check.Checked)
{
txtBox.Text=gv_enfant["yourColumnName",i].Value.ToString();
}

try it,
Front-End
<asp:CheckBox ID="CheckBoxenfant" runat="server" index="<%# Container.DataItemIndex %>" AutoPostBack="true" OnCheckedChanged="CheckBoxEnfants_CheckedChanged" />
<asp:TextBox ID="textbx" runat="server" Enabled="false" Text='<%# Eval("codeEnfants") %>' />
Code-behind
protected void CheckBoxEnfants_CheckedChanged(object s, EventArgs e)
{
byte index = byte.Parse((s as CheckBox).Attributes["index"]);
(gv_enfant.Rows[index].FindControl("textbx") as TextBox).Enabled = (gv_enfant.Rows[index].FindControl("CheckBoxenfant") as CheckBox).Checked;
}

Related

Without redirecting passing the querystring value to current page

I want to pass the query string value without redirecting to current page I have tried these code but I can even see the query string value variable to pass in these page.I have attached my code below.help me out from these problem
Thanks in advance
Aspx design code
<div class="col span_1_of_1">
<asp:GridView ID="gridweeks" runat="server" CssClass="grid" ShowHeaderWhenEmpty="True" ShowFooter="true" Style="width: 40%" AllowPaging="true" PageIndex="0" PageSize="5" AutoGenerateColumns="False" OnPageIndexChanging="gridweeks_PageIndexChanging">
<AlternatingRowStyle BackColor="#dddddd" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="weekmonth" HeaderText="Available Month" SortExpression="weekmonth" />
<asp:BoundField DataField="dayweek" HeaderText="Available Weeks" SortExpression="dayweek" />
<asp:TemplateField HeaderText="Edit / Delete">
<ItemTemplate>
<asp:LinkButton ID="lnkeditweek" runat="server" Style="color: black" CommandName="assign1" CommandArgument='<%#Eval("dayweek")+","+Eval("weekmonth")%>' OnClick="lnkeditweek_Click1"><i class="fa fa-pencil-square-o" style="color:#2389C9"></i></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#ffffff" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#32404E" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#32404E" ForeColor="White" HorizontalAlign="right" />
<RowStyle BackColor="#ffffff" BorderColor="#fff" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="batch" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [dayweek], [weekmonth] FROM [tblslots]"></asp:SqlDataSource>
</div>
C# code
LinkButton btn = (LinkButton)(sender);
lbltxt.Visible = true;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
try
{
if (btn.CommandName == "assign1")
{
string[] commandArgs = btn.CommandArgument.ToString().Split(new char[] { ',' });
zeroval = commandArgs[0];
firstval = commandArgs[1];
for (int j = 0; j < gridweeks.Rows.Count; j++)
{
GridViewRow gw = gridweeks.Rows[j];
//string months = gw.Cells[0].Text;
// string weeks = gw.Cells[1].Text;
for (int i = 0; i < gridsem.Rows.Count; i++)
{
GridViewRow gs = gridsem.Rows[i];
string semester = gs.Cells[0].Text;
lbltxt.Text = "You are going to edit for Section : " + Request.QueryString["section"] + ", Week : " + zeroval + " , Session : " + Request.QueryString["session"] + " , Semester : " + semester + " , Month : " + firstval + "";
mp5edit.Show();
}
}
string longurl = "viewavailableweeks.aspx?&ins=" + Request.QueryString["ins"] + "&section=" + Request.QueryString["section"] + "&session=" + Request.QueryString["session"] + "&academicyear=" + Request.QueryString["academicyear"] + "&month='" + firstval + "'+&week='" + firstval + "'";
var uriBuilder = new UriBuilder(longurl);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
longurl = uriBuilder.ToString();
}
}

Gridview datasource is null after postback

I have a page with a gridview that show article groups,and textbox and search button for search groups.
in this page if user not search anything ,grid view only show main groups(with parentId 0)
and else show every group that group name's contain textbox value.
My problem is when I search ,and then I want to update some row,GridView1_RowUpdating not fired...
I found that the problem is that gridview datasource not bound successfully.
how I fix this problem?
below is my source:
<asp:Label ID="Label1" runat="server" CssClass="txt" Text="searchgroups " ForeColor="#68a2d7"></asp:Label>
<asp:Label ID="Label2" runat="server" CssClass="txt" Text="group name" ForeColor="#68a2d7"></asp:Label>
<asp:TextBox ID="txtname" runat="server" CssClass="txt" Width="300px"></asp:TextBox>
<br/>
<asp:ImageButton ID="Ibtnsearch" runat="server" ImageAlign="Left" ImageUrl="../Icon/resize/search.gif"
OnClick="Ibtnsearch_Click" />
<br/>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="100%" CssClass="txt" AllowPaging="True"
OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCommand="GridView1_RowCommand1" PageSize="15" AllowSorting="True" OnSorting="GridView1_Sorting">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="chid" SortExpression="chid" HeaderText="ID" />
<asp:BoundField DataField="chname" SortExpression="chname" HeaderText="Name" />
<asp:HyperLinkField DataNavigateUrlFields="chid,cLanguage" DataNavigateUrlFormatString="../default.aspx?pnl=lstcatChat&nParentid_fk={0}&lang={1}"
Text="Sub Groups" HeaderText="Show Sub Grups">
<ControlStyle CssClass="link" />
</asp:HyperLinkField>
<asp:CommandField CausesValidation="false" ButtonType="Image" EditImageUrl="~/Icon/silk/application_edit.gif"
ShowEditButton="True" CancelImageUrl="~/Icon/silk/arrow_undo.gif" UpdateImageUrl="~/Icon/silk/accept.gif"
EditText="Edit" HeaderText="Edit" />
</Columns>
<RowStyle BackColor="#e8edf2" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="White" ForeColor="#333333" HorizontalAlign="Center" BorderColor="White"
Font-Bold="True" Font-Names="Tahoma" Font-Overline="False" Font-Size="X-Small"
Font-Underline="False" />
<HeaderStyle BackColor="#68a2d7" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="White" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView>
and in my code page:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = Search_groups();
GridView1.DataBind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.DataSource = Search_groups();
if (GridViewSortExpresion != null && GridViewSortExpresion != "")
SortGridView(GridViewSortExpresion, GridViewSortDirection);
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.DataSource = Search_groups();
if (GridViewSortExpresion != null && GridViewSortExpresion != "")
SortGridView(GridViewSortExpresion, GridViewSortDirection);
GridView1.EditIndex = -1;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gvr = GridView1.Rows[e.RowIndex];
using (_Category nc = new _Category())
{
if (Request["lang"] == "" || Request["lang"] == null)
nc.Language = "fa";
else
nc.Language = Request["lang"];
DataTable dt2 = new DataTable();
dt2 = Search_groups();
int ncid = (int)dt2.Rows[e.RowIndex]["chid"];
ncid = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
nc.ID = ncid;
nc.Name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
nc.Updatefast();
GridView1.DataSource = Search_groups();
if (GridViewSortExpresion != null && GridViewSortExpresion != "")
SortGridView(GridViewSortExpresion, GridViewSortDirection);
GridView1.EditIndex = -1;
GridView1.DataBind();
dt2.Dispose();
gvr.Dispose();
}
}
protected void Ibtnsearch_Click(object sender, ImageClickEventArgs e)
{
GridView1.DataSource = Search_groups();
if (GridViewSortExpresion != null && GridViewSortExpresion != "")
SortGridView(GridViewSortExpresion, GridViewSortDirection);
GridView1.DataBind();
}
private DataTable Search_groups()
{
if (Request["nParentid_fk"] != null)
parent_fk = Convert.ToInt32(Request["nParentid_fk"]);
else
parent_fk = 0;
using (_Category nc = new _Category())
{
if (Request["lang"] == "" || Request["lang"] == null)
nc.Language = "fa";
else
nc.Language = Request["lang"];
if (txtname.Text != "")
return nc.search_allcategories(txtname.Text);
else
return nc.Select_parentid_fk(parent_fk);
}
}
public string GridViewSortDirection
{
get
{
//if (ViewState["sortDirection"] == null)
// ViewState["sortDirection"] = SortDirection.Ascending;
//return (SortDirection)ViewState["sortDirection"];
if (SortDirection.Value == null)
SortDirection.Value = "asc";
return SortDirection.Value;
}
set { SortDirection.Value = value; }
}
public string GridViewSortExpresion
{
get
{
//if (ViewState["SortExpresion"] == null)
// ViewState["SortExpresion"] = "";
//if (ViewState["SortExpresion"] != null)
// return ViewState["SortExpresion"].ToString();
//else
// return null;
if (SortExpresion.Value != null)
return SortExpresion.Value.ToString();
else
return null;
}
set { SortExpresion.Value = value; }
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//DataTable dataTable = GridView1.DataSource as DataTable;
GridViewSortExpresion = e.SortExpression;
if (GridViewSortDirection == "asc")
{
GridViewSortDirection = "desc";
SortGridView(GridViewSortExpresion, GridViewSortDirection);
}
else
{
GridViewSortDirection = "asc";
SortGridView(GridViewSortExpresion, GridViewSortDirection);
}
}
private void SortGridView(string sortExpression, string direction)
{
// You can cache the DataTable for improving performance
//DataTable dt = GridView1.DataSource as DataTable;
DataTable dt = Search_groups();
DataView dv = new DataView(dt);
dv.Sort = sortExpression + " " + direction;
GridView1.DataSource = dv;
GridView1.DataBind();
}
when I try to update ,I get this error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Edit 2
Now I found that my problem is that gridview loses datasource on post back ,
I search but I not found solution.I don't want to use session or viewstate,because I have a lot of tables like above ,What is the solution?
set following property:
set AutoGenerateEditButton="False"
Try putting:
<asp:TemplateField>
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" commandname="Edit" text="Edit" />
<asp:Button id="btnDelete" runat="server" commandname="Delete" text="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button id="btnUpdate" runat="server" commandname="Update" text="Update" />
<asp:Button id="btnCancel" runat="server" commandname="Cancel" text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
In place of :
<asp:CommandField CausesValidation="false" ButtonType="Image" EditImageUrl="~/Icon/silk/application_edit.gif"
ShowEditButton="True" CancelImageUrl="~/Icon/silk/arrow_undo.gif" UpdateImageUrl="~/Icon/silk/accept.gif"
EditText="Edit" HeaderText="Edit" />

Can't get value from radio button on gridview on C#

Hello i have a Gridview with 4 radio buttons and i want to get the value from them, and no matter what i do the value is always false, could someone tellme where is my mistake?
This is the code of the gridview:
<asp:GridView ID="GridView8" runat="server" Width="903px"
Height="516px" CellPadding="4" ForeColor="#333333" GridLines="None"
Visible="False"
>
<AlternatingRowStyle BorderColor="Black" BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Solicitante/">
<ItemTemplate>
<asp:RadioButton ID="optCl1" runat="server" Text="SI" GroupName="optCl" />
<asp:RadioButton ID="optCl2" runat="server" Text="NO" GroupName="optCl" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CoGarante">
<ItemTemplate >
<asp:RadioButton ID="optGar1" runat="server" Text="SI" GroupName="optGar" />
<asp:RadioButton ID="optGar2" runat="server" Text="NO" GroupName="optGar" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BorderColor="Black" />
<FooterStyle BackColor="#990000" BorderColor="Black" ForeColor="White"
Font-Bold="True" />
<HeaderStyle BackColor="#990000" BorderColor="Black" Font-Bold="True"
ForeColor="White" />
<PagerStyle ForeColor="#333333" HorizontalAlign="Center" BackColor="#FFCC66" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
The code of the function that read the radiobutton
protected void saveQuestions()
{
foreach (GridViewRow row in GridView8.Rows)
{
RadioButton rb = row.Cells[2].FindControl("optGar2") as RadioButton;
Response.Write(rb.Checked);
}
conn.Close();
}
The code of the function that set the data on the gridview:
protected void loadQuestions()
{
OdbcConnection conn = connection();
conn.Open();
OdbcCommand findSql = new OdbcCommand("SELECT question AS PREGUNTAS,id FROM questionary_reg WHERE(status='1')", conn);
GridView8.DataSource = null;
DataTable dt = new DataTable();
dt.Load(findSql.ExecuteReader());
GridView8.DataSource = dt;
GridView8.DataBind();
conn.Close();
}
The problem because happen postback and reset the values inside the gridview, make sure you
call this function loadQuestions() on if !Postback ONLY
if(!IsPostBack){
loadQuestions();
}
#UPDATE 1 WORKING CODE :
//Design
<asp:GridView runat="server" ID="gv">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton runat="server" ID="rd" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button runat="server" ID="btn" onclick="btn_Click" />
//Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStringDb1"].ToString()))
{
try
{
String cmdText = "SELECT * FROM Image WHERE IsDeleted=#isDeleted";
SqlCommand cmd = new SqlCommand(cmdText, cn);
cmd.Parameters.AddWithValue("#IsDeleted", "false");
cn.Open();
SqlDataAdapter myAdapter = new SqlDataAdapter(cmd);
DataTable dt_Category = new DataTable();
myAdapter.Fill(dt_Category);
cn.Close();
gv.DataSource = dt_Category;
gv.DataBind();
}
catch (Exception ex)
{
}
}
}
}
protected void btn_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in gv.Rows)
{
RadioButton rd = (RadioButton)gvr.FindControl("rd");
if (rd.Checked)
{
}
else
{
}
}
}
Maybe you need a 'CheckedChanged' event: (Tested and working)
In ASPX set (in this example, you can to see label display the number of row selected)
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbtnSelect" AutoPostBack="true" runat="server" OnCheckedChanged="rbtnSelect_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
and code-behing set
protected void rbtnSelect_CheckedChanged(object sender, EventArgs e)
{
RadioButton selectButton = (RadioButton)sender;
GridViewRow row = (GridViewRow)selectButton.Parent.Parent;
int a = row.RowIndex;
foreach (GridViewRow rw in gvCursos.Rows)
{
if (selectButton.Checked)
{
if (rw.RowIndex != a)
{
lbResultado.Text = rw.RowIndex.ToString();
RadioButton rd = rw.FindControl("rbtnSelect") as RadioButton;
rd.Checked = false;
}
}
}
}
Change this:
RadioButton rb = row.Cells[2].FindControl("optGar2") as RadioButton;
To this:
RadioButton rb = row.FindControl("optGar2") as RadioButton;
for (int i = 0; i < GridView8.Rows.Count; i++)
{
if (GridView8.Rows[i].RowType == DataControlRowType.DataRow)
{
RadioButton rb= (RadioButton)grdView.Rows[i].FindControl("optGar2");
Response.Write(rb.Checked);
}
}
foreach (GridViewRow gvp in gridView1.Rows)
{
System.Web.UI.HtmlControls.HtmlInputRadioButton rd = (System.Web.UI.HtmlControls.HtmlInputRadioButton)gvp.FindControl("rd");
if (rd.Checked)
{
string s = rd.Value;
}
else
{
}
}
design view
<ItemTemplate>
<input runat="server" id='rd' type="radio" value='<%# Eval("id") %>' onclick="javascript:SelectSingleRadiobutton(this.id)" />
</ItemTemplate>

Gridview in Modal Popup Extender- Postback Issues?

I have a C# .Net application with a gridview within an Ajax Modal Popup (VS2008). I have the grid view set to return 10 records per page with paging enabled.
When the user clicks to change page within the gridview there is a postback which closes the modal window and then opens it again using ModalPopup.show();
Is there any way to avoid the postback of the whole page and just postback the gridview whilst keeping the modal window active? At the moment the postback of the whole page gives the impression of flicker...
<asp:Panel ID="Panel1" runat="server" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Small" ForeColor="#82B8DE">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
onpageindexchanging="GridView1_PageIndexChanging"
onrowdatabound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged"
SelectedIndex="0" ShowHeader="False" Width="700px" ControlID="GridView1"
EventName="PageIndexChanging" Font-Italic="True" Font-Names="Times New Roman"
Font-Size="Medium">
<PagerSettings PageButtonCount="12" />
<RowStyle CssClass="RowStyle" BackColor="#EFF3FB" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Small" ForeColor="#82B8DE" />
<Columns>
<asp:BoundField DataField="Address" ReadOnly="True">
<ItemStyle Width="385px" />
</asp:BoundField>
<asp:BoundField DataField="XCoord" ReadOnly="True" ShowHeader="False" >
<ItemStyle CssClass="Hidden" />
</asp:BoundField>
<asp:BoundField DataField="YCoord" ReadOnly="True" ShowHeader="False" >
<ItemStyle CssClass="Hidden" />
</asp:BoundField>
</Columns>
<FooterStyle CssClass="FooterStyle" BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle CssClass="SelectedRowStyle" BackColor="#D1DDF1"
Font-Bold="True" ForeColor="#333333" />
<HeaderStyle CssClass="HeaderStyle" BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#2461BF" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Panel>
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" TargetControlID="dummy"
BackgroundCssClass="ModalBackgroundGrid" BehaviorID="ModalGrid">
</ajax:ModalPopupExtender>
And the code behind...
public void Page_Load(object sender, EventArgs e)
{
try
{
if (!(Page.IsPostBack))
{
GridView1.EnableViewState = true;
GridView1.AllowPaging = true;
GridView1.PageSize = 10;
GridView1.PagerSettings.Mode = PagerButtons.Numeric;
GridView1.Visible = true;
}
if (!m_bDisclaimerShown)
{
m_bDisclaimerShown = true;
mpe1.Show();
TabContainer.Visible = true;
ScaleBar1.Visible = true;
}
}
catch (Exception ex)
{
ShowMsg("Error - " + ex.Message);
}
}
protected void btnHide_Click(object sender, EventArgs e)
{
mpe1.Hide();
TabContainer.Visible = true;
ScaleBar1.Visible = true;
}
protected void cmdZoomAddress_Click(object sender, EventArgs e)
{
try
{
if (txtPostCode.Text.Length >= 7 && OpenDB())
{
string strPostcode = txtPostCode.Text;
strPostcode = strPostcode.Substring(0, 4) + strPostcode.Substring(strPostcode.Length - 3, 3);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = m_sqlConn;
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
sqlCmd.CommandText = "sde.dbo.sp_selAddressByPostcode";
sqlCmd.Parameters.Add("#Postcode", SqlDbType.VarChar);
sqlCmd.Parameters["#Postcode"].Value = strPostcode;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);
m_sqlDataTable = new DataTable();
sqlAdapter.Fill(m_sqlDataTable);
GridView1.DataSource = m_sqlDataTable;
GridView1.DataBind();
GridView1.Visible = true;
ModalPopupExtender1.Show();
}
else
{
ShowMsg("Error - No Postal Addresses Returned");
}
}
catch (Exception ex)
{
ShowMsg("Error - " + ex.Message);
}
finally
{
CloseDB();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (sender != null)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = m_sqlDataTable;
GridView1.DataBind();
ModalPopupExtender1.Show();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow GVRow = GridView1.SelectedRow;
int iX = (int)Convert.ToSingle(GVRow.Cells[1].Text);
int iY = (int)Convert.ToSingle(GVRow.Cells[2].Text);
GridView1.Visible = false;
MoveMap(iX, iY);
}
public void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItemIndex >= 0)
{
e.Row.Attributes["style"] = "cursor:pointer";
e.Row.Attributes.Add("onMouseOver", "this.style.cursor='hand';");
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));
}
}
protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow r in GridView1.Rows)
{
if (r.RowType == DataControlRowType.DataRow)
{
Page.ClientScript.RegisterForEventValidation(GridView1.UniqueID, "Select$" + r.RowIndex);
}
}
base.Render(writer);
}
thanks for your suggestion. I've put the gridview into a...
<asp:UpdatePanel>
<ContentTemplate>
The modal now stays however when I click a record in the grid view it doesn't close!

Column Ambiguously Defined Error in Oracle Query

I have a code like this.
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Calculate.Visible = false;
MV_Label.Visible = false;
RISK_Label.Visible = false;
KV_Label.Visible = false;
}
protected void Calculate_Click(object sender, EventArgs e)
{
MV_Label.Visible = true;
RISK_Label.Visible = true;
Calculate.Visible = true;
KV_Label.Visible = true;
double sumMV = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField2");
if (cb.Checked == true)
{
double amount = Convert.ToDouble(gvr.Cells[9].Text);
sumMV += amount;
}
}
MV_Label.Text = sumMV.ToString();
double sumRISK = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField1");
if (cb.Checked == true)
{
double amount = Convert.ToDouble(gvr.Cells[7].Text);
sumRISK += amount;
}
}
RISK_Label.Text = sumRISK.ToString();
double sumKV = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField3");
if (cb.Checked == true)
{
double amount = Convert.ToDouble(gvr.Cells[11].Text);
sumKV += amount;
}
}
KV_Label.Text= sumRISK.ToString();
}
protected void SendToGridview_Click(object sender, EventArgs e)
{
DateTime dt_stb;
Calculate.Visible = true;
MV_Label.Visible = true;
RISK_Label.Visible = true;
KV_Label.Visible = true;
string strQuery = string.Empty;
string ConnectionString = ConfigurationManager.ConnectionStrings["ora"].ConnectionString;
OracleConnection myConnection = new OracleConnection(ConnectionString);
string txtBoxText1 = ((TextBox)Page.FindControl("TextBox1")).Text;
if (txtBoxText1 != "")
{
strQuery = #"SELECT A.HESAP_NO, A.TEKLIF_NO1 || '/' || A.TEKLIF_NO2 AS TEKLIF, A.MUS_K_ISIM AS MUSTERI,
B.MARKA, C.SASI_NO, C.SASI_DURUM, D.TAS_MAR, NVL(RISK_SASI(A.TEKLIF_NO1, A.TEKLIF_NO2, C.URUN_SIRA_NO, C.SIRA_NO, :S_TARIH_B),0) AS RISK,
NVL(MV_SASI(A.TEKLIF_NO1, A.TEKLIF_NO2, C.SIRA_NO, C.URUN_SIRA_NO, :S_TARIH_B),0) AS MV,
MV_K(TEKLIF_NO1,TEKLIF_NO2, :S_TARIH_B) AS KV
FROM S_TEKLIF A, S_URUN B, S_URUN_DETAY C, KOC_KTMAR_PR D
WHERE A.TEKLIF_NO1 || A.TEKLIF_NO2 = B.TEKLIF_NO1 || B.TEKLIF_NO2
AND A.TEKLIF_NO1 || A.TEKLIF_NO2 = C.TEKLIF_NO1 || C.TEKLIF_NO2
AND B.SIRA_NO = C.URUN_SIRA_NO
AND B.DISTRIBUTOR = D.DIST_KOD
AND B.MARKA = D.MARKA_KOD
AND B.URUN_KOD = D.TAS_KOD ";
}
string param = "";
foreach (ListItem l in CheckBoxList1.Items)
{
if (l.Selected)
{
param += string.Format("'{0}'", l.Value);
param += ",";
}
}
param = param.Remove(param.Length - 1);
strQuery = strQuery + " AND A.HESAP_NO IN (" + param + ")";
OracleCommand myCommand = new OracleCommand(strQuery, myConnection);
myCommand.CommandType = System.Data.CommandType.Text;
myCommand.Connection = myConnection;
myCommand.CommandText = strQuery;
dt_stb = DateTime.Parse(txtBoxText1);
myCommand.Parameters.AddWithValue(":S_TARIH_B", dt_stb);
myConnection.Open();
OracleDataReader dr = myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
GridView1.DataSource = dr;
GridView1.DataBind();
GridView1.Visible = true;
myConnection.Close();
double sumMV = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField2");
if (cb.Checked == true)
{
double amount = Convert.ToDouble(gvr.Cells[9].Text);
sumMV += amount;
}
}
MV_Label.Text = sumMV.ToString();
double sumRISK = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField1");
if (cb.Checked == true)
{
double amount = Convert.ToDouble(gvr.Cells[7].Text);
sumRISK += amount;
}
}
RISK_Label.Text = sumRISK.ToString();
double sumKV = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("NameCheckBoxField3");
if (cb.Checked == true)
{
double amount = Convert.ToDouble(gvr.Cells[11].Text);
sumKV += amount;
}
}
KV_Label.Text = sumRISK.ToString();
}
</script>
<!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">
#form1
{
height: 729px;
width: 1083px;
}
.style1
{
width: 265px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<br />
<img src="../images/Scania_Logo.gif" style="height: 49px; width: 193px" />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large"
ForeColor="Blue" Height="40px" Text="BV & RISK SIMULATOR"
Width="329px" style="text-align: center"></asp:Label>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<br />
<div style="OVERFLOW-Y:scroll; WIDTH:362px; HEIGHT:177px">
<br />
<table border="5" bordercolor=blue style="height: 116px; width: 343px">
<tr>
<td class="style1">
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="ChechkBoxDataSource" DataTextField="MUS_K_ISIM"
DataValueField="HESAP_NO" Font-Size="12pt">
</asp:CheckBoxList>
</td>
</tr>
</table>
</div>
<div style="width: 331px">
<br />
<asp:Textbox ID="TextBox1" runat="server" Font-Size="X-Small" Height="13px" Font-Names="Verdana" Width="75px" ></asp:Textbox>
<asp:CalendarExtender Format="dd/MM/yyyy" ID="TextBox1_CalendarExtender" runat="server"
TargetControlID="TextBox1">
</asp:CalendarExtender>
<asp:Image ID="ImageButton3" runat="server" ImageUrl="~/images/SmallCalendar.gif"/>
<br />
</div>
<asp:SqlDataSource ID="ChechkBoxDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ora %>"
ProviderName="<%$ ConnectionStrings:ora.ProviderName %>"
SelectCommand="SELECT DISTINCT(A.HESAP_NO),A.MUS_K_ISIM
FROM S_TEKLIF A
ORDER BY A.MUS_K_ISIM">
</asp:SqlDataSource>
<br />
<asp:Button ID="SendToGridview" runat="server" Text="Send" Width="59px"
onclick="SendToGridview_Click" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server"
Width="16px" CellPadding="4"
GridLines="None" Height="16px" ForeColor="#333333"
AutoGenerateColumns="False" DataKeyNames="RISK,MV" BorderColor="White"
BorderStyle="Ridge" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField HeaderText="HESAP" DataField="HESAP_NO" />
<asp:BoundField HeaderText="TEKLIF" DataField="TEKLIF" />
<asp:BoundField HeaderText="MUSTERI" DataField="MUSTERI" />
<asp:BoundField HeaderText="MARKA" DataField="MARKA" />
<asp:BoundField HeaderText="SASI" DataField="SASI_NO" />
<asp:BoundField HeaderText="DURUM" DataField="SASI_DURUM" />
<asp:BoundField HeaderText="TASIT MARKA" DataField="TAS_MAR" />
<asp:BoundField HeaderText="RISK" DataField="RISK" />
<asp:templatefield headertext="">
<itemtemplate>
<asp:CheckBox DataField="NameCheckBoxField1" ID="NameCheckBoxField1" Checked="True" runat="server"></asp:CheckBox>
</itemtemplate>
</asp:templatefield>
<asp:BoundField HeaderText="MV" DataField="MV" />
<asp:templatefield headertext="">
<itemtemplate>
<asp:CheckBox DataField="NameCheckBoxField2" ID="NameCheckBoxField2" Checked="True" runat="server"></asp:CheckBox>
</itemtemplate>
</asp:templatefield>
<asp:BoundField HeaderText="KV" DataField="KV" />
<asp:templatefield headertext="">
<itemtemplate>
<asp:CheckBox DataField="NameCheckBoxField3" ID="NameCheckBoxField3" Checked="True" runat="server"></asp:CheckBox>
</itemtemplate>
</asp:templatefield>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<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="#F4F4FD" />
<sortedascendingheaderstyle backcolor="#5A4C9D" />
<sorteddescendingcellstyle backcolor="#D8D8F0" />
<sorteddescendingheaderstyle backcolor="#3E3277" />
<SortedAscendingCellStyle BackColor="#F5F7FB"></SortedAscendingCellStyle>
<SortedAscendingHeaderStyle BackColor="#6D95E1"></SortedAscendingHeaderStyle>
<SortedDescendingCellStyle BackColor="#E9EBEF"></SortedDescendingCellStyle>
<SortedDescendingHeaderStyle BackColor="#4870BE"></SortedDescendingHeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ora %>"
ProviderName="<%$ ConnectionStrings:ora.ProviderName %>"
SelectCommand=" SELECT A.HESAP_NO, A.TEKLIF_NO1 || '/' || A.TEKLIF_NO2 AS TEKLIF, A.MUS_K_ISIM ,
B.MARKA, C.SASI_NO, C.SASI_DURUM, D.TAS_MAR, NVL(RISK_SASI(A.TEKLIF_NO1, A.TEKLIF_NO2, C.URUN_SIRA_NO, C.SIRA_NO, :S_TARIH_B),0) AS RISK,
NVL(MV_SASI(A.TEKLIF_NO1, A.TEKLIF_NO2, C.URUN_SIRA_NO, C.SIRA_NO, :S_TARIH_B),0) AS MV,
MV_K(A.TEKLIF_NO1,A.TEKLIF_NO2, :S_TARIH_B) AS KV, 'NameCheckBoxField1' = 0x1, 'NameCheckBoxField2' = 0x1, 'NameCheckBoxField3' = 0x1
FROM S_TEKLIF A, S_URUN B, S_URUN_DETAY C, KOC_KTMAR_PR D
WHERE A.TEKLIF_NO1 || A.TEKLIF_NO2 = B.TEKLIF_NO1 || B.TEKLIF_NO2
AND A.TEKLIF_NO1 || A.TEKLIF_NO2 = C.TEKLIF_NO1 || C.TEKLIF_NO2
AND B.SIRA_NO = C.URUN_SIRA_NO
AND C.SASI_DURUM IN ('A','R')
AND B.DISTRIBUTOR = D.DIST_KOD
AND B.MARKA = D.MARKA_KOD
AND B.URUN_KOD = D.TAS_KOD ">
</asp:SqlDataSource>
<br />
<asp:Button ID="Calculate" runat="server" onclick="Calculate_Click"
Text="Calculate" />
<asp:Label ID="RISK_Label" runat="server" Font-Bold="True" ForeColor="#3333FF"></asp:Label>
<asp:Label ID="MV_Label" runat="server" Font-Bold="True" ForeColor="#3333FF"></asp:Label>
<asp:Label ID="KV_Label" runat="server" Font-Bold="True" ForeColor="#3333FF"></asp:Label>
<br />
<br />
</form>
</body>
</html>
BUT when i run this page i getting an error like this.
ORA-00918: column ambiguously defined
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OracleClient.OracleException: ORA-00918: column ambiguously defined
Source Error:
Line 128: myConnection.Open();
Line 129:
Line 130: OracleDataReader dr = myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
Line 131:
Line 132: GridView1.DataSource = dr;
Probably right here MV_K(TEKLIF_NO1,TEKLIF_NO2, :S_TARIH_B) AS KV. It should be something like MV_K(A.TEKLIF_NO1,A.TEKLIF_NO2, :S_TARIH_B) AS KV since that column exists in A,B and C
You used table aliases and multiple tables but you did not use table alias prefixes in front of all fields. This is a typical situation where you get ambiguous columns.

Categories