Category Archives: GridView

[RESOLVED] Databinding asp:calendar control

Is it possible to make asp:calendar control databindable to SQL database? Like GridView or ListView. I don't see how to do it and find it unbelievable. Or is there third party calendar control that is easy to use?

IgorB

Is it possible to make asp:calendar control databindable to SQL database?
 

What do you want to bind in calendar control? are you looking to select dates in calendar depending on SQL data? If so check DayRender Event(This event is raised when each day is created in the control hierarchy for the Calendar control.)

Ps:You may find this article useful..

http://odetocode.com/Articles/223.aspx

[RESOLVED] Avoid loding data when user unselect

I have checkbox control in Gridview when i selected checkbox entire row will be loaded into corresponding Textboxes, up to here every thing fine when i unchecked again entire row is populating/loading into corresponding Textboxes i dont want to be happen this when i unchecked data should not be loaded.

Anothere one is if i checked "A" record earlier, simulataniously when i checked "B" record "A" record should be un checked automatically but for me it is not happening both records are checked.

how can i acheive above to please help,Thanks

Gridview with checkbox

<asp:GridView ID="GVStatus" runat="server" CellPadding="3" ForeColor="#333333"
            GridLines="Vertical" Height="16px" Width="180px"  AutoGenerateColumns="false"
            EnableModelValidation="True" style="margin-top: 0px" Font-Size="Medium"
                   ToolTip="List of Jobs  from the Database">
             <RowStyle BackColor="#EFF3FB" />
             <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
             <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
             <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
             <HeaderStyle  BackColor="#507CD1"  Width="50px" Font-Bold="True" ForeColor="White" />
             <EditRowStyle BackColor="#2461BF" />
             <AlternatingRowStyle BackColor="White" />
             <Columns>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" QuotesKey='<%#Eval("WONumber").ToString() %>' OnCheckedChanged="chkSelect_CheckedChanged"  />
                     </ItemTemplate>
                 </asp:TemplateField>
 </Columns>


 

Hi,

 

Show us your  chkSelect_CheckedChanged method.


Protected Sub chkSelect_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim indx As Integer
        Dim connectionString As String = "Database=pjt;" & "Data Source=localhost;" & "User Id=root;Password=prasad123"
        Dim query As String = "Select WONumber,PartNumber,Rev,customer,CRep,AEng,Orderqty,PReceived,FabDue,FabComp,AssyDue,AssyComp,TestDue,TestComp,Notes,Shippedqty,status from status"
        'Dim query As String = "Select partnumber from status"
        Dim connection As New MySqlConnection(connectionString)
        Dim da As New MySqlDataAdapter(query, connection)
        Dim ds As New DataSet()        Dim myAdapter As New MySqlDataAdapter
        myAdapter = New MySqlDataAdapter(query, connection)
        myAdapter.Fill(ds, "status")
        Dim dt As DataTable = New DataTable() 'DataTable Initializes a new instance of the DataTable class with no arguments.
        da.Fill(dt)        Dim checkbox As CheckBox = CType(sender, CheckBox)
        Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)
        Dim i As Integer        For i = 0 To dt.Rows.Count - 1 Step i + 1
            If (dt.Rows(i)("WONumber").ToString = row.Cells(1).Text.ToString()) Then
                indx = i            End If        Next
        txtWON.Text = dt.Rows(indx)("WONumber").ToString()
        txtPartNumber.Text = dt.Rows(indx)("PartNumber").ToString()
        txtRev.Text = dt.Rows(indx)("Rev").ToString()
        txtCust.Text = dt.Rows(indx)("Customer").ToString()
        DDCR.Text = dt.Rows(indx)("CRep").ToString()
        DDAE.Text = dt.Rows(indx)("AEng").ToString()
        txtOQty.Text = dt.Rows(indx)("OrderQty").ToString()
        DDPR.Text = dt.Rows(indx)("PReceived").ToString
        txtFDD.Text = dt.Rows(indx)("FabDue").ToString()
        txtFCD.Text = dt.Rows(indx)("FabComp").ToString()
        txtADD.Text = dt.Rows(indx)("AssyDue").ToString
        txtACD.Text = dt.Rows(indx)("AssyComp").ToString()
        txtTDD.Text = dt.Rows(indx)("TestDue").ToString()
        txtTCD.Text = dt.Rows(indx)("TestComp").ToString()
        txtDes.Text = dt.Rows(indx)("Notes").ToString()
        txtShipQty.Text = dt.Rows(indx)("ShippedQty").ToString()
        DDStatus.Text = dt.Rows(indx)("Status").ToString()    End Sub

Hi, Give your chkSelect_CheckedChanged event handler as below.

 

1. First you clear your textboxes.

2. In the loop, you uncheck previous checkboxes

3. Finally if you have checked any checkbox, then that line will have its value filled in the textboxes.

Just make sure that you are using the same query for filling the datatable and also for binding the gridview.

Hope this helps.

 

 

Protected Sub chkSelect_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        txtWON.Text = ""        txtPartNumber.Text = ""        txtRev.Text = ""
        txtCust.Text = ""        DDCR.Text = ""        DDAE.Text = ""
        txtOQty.Text = ""        DDPR.Text = ""        txtFDD.Text = ""
        txtFCD.Text = ""        txtADD.Text = ""        txtACD.Text = ""
        txtTDD.Text = ""        txtTCD.Text = ""        txtDes.Text = ""
        txtShipQty.Text = ""        DDStatus.Text = ""
        Dim indx As Integer
        Dim connectionString As String = "Database=pjt;" & "Data Source=localhost;" & "User Id=root;Password=prasad123"
        Dim query As String = "Select WONumber,PartNumber,Rev,customer,CRep,AEng,Orderqty,PReceived,FabDue,FabComp,AssyDue,AssyComp,TestDue,TestComp,Notes,Shippedqty,status from status"
        'Dim query As String = "Select partnumber from status"
        Dim connection As New MySqlConnection(connectionString)
        Dim da As New MySqlDataAdapter(query, connection)
        Dim ds As New DataSet()        Dim myAdapter As New MySqlDataAdapter
        myAdapter = New MySqlDataAdapter(query, connection)
        myAdapter.Fill(ds, "status")
        Dim dt As DataTable = New DataTable() 'DataTable Initializes a new instance of the DataTable class with no arguments.
        da.Fill(dt)        Dim checkbox As CheckBox = CType(sender, CheckBox)
        Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)
        Dim i As Integer        For i = 0 To dt.Rows.Count - 1 Step i + 1
            If (dt.Rows(i)("WONumber").ToString = row.Cells(1).Text.ToString()) Then
                indx = i            Else
                Dim loopCheckBox As CheckBox = CType(GVStatus.Rows(i).Cells(0).Controls(1), CheckBox)
                loopCheckBox.Checked = False            End If        Next
        If (checkbox.Checked) Then
            txtWON.Text = dt.Rows(indx)("WONumber").ToString()
            txtPartNumber.Text = dt.Rows(indx)("PartNumber").ToString()
            txtRev.Text = dt.Rows(indx)("Rev").ToString()
            txtCust.Text = dt.Rows(indx)("Customer").ToString()
            DDCR.Text = dt.Rows(indx)("CRep").ToString()
            DDAE.Text = dt.Rows(indx)("AEng").ToString()
            txtOQty.Text = dt.Rows(indx)("OrderQty").ToString()
            DDPR.Text = dt.Rows(indx)("PReceived").ToString
            txtFDD.Text = dt.Rows(indx)("FabDue").ToString()
            txtFCD.Text = dt.Rows(indx)("FabComp").ToString()
            txtADD.Text = dt.Rows(indx)("AssyDue").ToString
            txtACD.Text = dt.Rows(indx)("AssyComp").ToString()
            txtTDD.Text = dt.Rows(indx)("TestDue").ToString()
            txtTCD.Text = dt.Rows(indx)("TestComp").ToString()
            txtDes.Text = dt.Rows(indx)("Notes").ToString()
            txtShipQty.Text = dt.Rows(indx)("ShippedQty").ToString()
            DDStatus.Text = dt.Rows(indx)("Status").ToString()        End If
    End Sub

 

Wow pretty precise solution Lateef,Thank you so much,Have a Great day.

[RESOLVED] call the code begind method in a aspx page

hello,

       how can we call the code begind method in a aspx page?

for ex:

code behind:

==========

public bool sample()
        {
            return true;
        }

 

aspx:

===========

<asp:CheckBox ID="chkPFCeilingFlag" runat="server" TabIndex="15" Checked='<%# sample() %>'
Enabled="true" CssClass="CheckBox"></asp:CheckBox>

but it is not called.

 

hi,

 this.chkPFCeilingFlag.DataBind();

 bcos this '<%# sample() %>' code will be executed while calling databind()

Hello,


You can set the Checked property of CheckBox on PageLoad event like this:

<asp:CheckBox ID="chkPFCeilingFlag" runat="server" TabIndex="15" Enabled="true" CssClass="CheckBox"></asp:CheckBox>


<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        If Not Page.IsPostBack Then</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            chkPFCeilingFlag.Checked = sample()</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        End If</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">    End Sub</div>

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        { 

              chkPFCeilingFlag.Checked = sample();

        }

    }


Please mark as Answer if it helps you.....Nitesh Garg

As the two people above me have stated, when you use <%# %>, it will perform these actions on the databinding event for the containing control.

I don't see why you would actually want to do it like this and not in the code behind, as this just seems to be a sloppy method to achieve whatever it is that you want.

Seeing as this isn't a dynamic control inside a template for a gridview/dataview/... you should probably just set the value in the page_load event.

you have to call chkPFCeilingFlag.DataBind() in page Load event

thanks


As per looking your code I dont understand what is the requiremet to write this kind of code in aspx page that you can achieve easily by writing it in page_load event.

 

But anyways...  Checked='<%# sample() %>' this want works to achieve from aspx page you can do it from javascript by following code.

function AlertMessage() {


            if ('<%=sample() %>' == 'True');
            {
               document.getElementById('chkPFCeilingFlag').checked = 1;
                

            }
        }


After that you need to call this function after in your page but make sure call this function in after your control load mean write this function exection code after the checkbox conrols aspx code (by line no)

 

Mark as answer if this answer for your question

nice.it is worked.if that function is in another one class then how can we call it.


If your current problem has been solved, mark the thread as resolved or mark the post as an answer. Start a new thread for new question.

The javascript method is not the best approach, as you know what you want to render, and it won't work is javascript is turned of.

server controls (those with a runat=server) only support binding expressions. if you want to use binding expressions, for a page where the controls are not in a repeater, etc, in page load you can just call:

  Page.DataBind();

if you want more control, (say you have a repeater), just wrap the controls you want to databind, in a panel, then call databind() on the panel in page load.

  pnlName.DataBind();

of course you could just call databind on the one control.

 cntName.DataBind()

and any expressions on it will work.


[RESOLVED] Sending Data Between Iframes.

Hi

I've got a situation where there is a page with 3 iframes. The first frame contains a TreeView, the second a GridView which is dependent on the selected node of the Treeview in frame 1 and the third frame contains labels with information also dependent on the TreeView in the first frame.

My problem is, how do I pass information from the first frame to the others? Can I access information about the selected node in JavaScript, pass it to another frame and then do a postback with the info as an argument?


Thanks

Hi

You can see explaination here from

sharing variables between windows and frames

accessing variables from one frame to another

Now, sharing variables between frames is not really any different than sharing them between windows. All you need is a reference to the frame object.

For example, if a window has two frames, the first frame can access a variable in the second frame using the following expression:

Example: first frame accessing second frame's variable

parent . frames [1] .
variable_name

Similarly, the second frame can access variables in the first frame through the following expression:

Example: second frame accessing first frame's variable

parent . frames [0] . 
variable_name

As illustrated in these examples, frames can obtain references to neighboring frames through the parent window's

frames []
property. Don't forget that the first frame in this array is indexed with 0, not 1.


Regards

shabir

Hi

Thanks, I have no problem passing JavaScript variables between frames, the problem is how do I pass info from the server control to JavaScript? I've been experimenting with the IscriptControl interface, I'd like to bind a function to the window's onload event so after the user clicks on the TreeFrame it does a postback and when the window has finished loading it can pass the selected node onto the other frame with the gridview.

Regards

Hi,

You can consider to pass value between Iframe by using QueryString in Iframe src property.

Like:

<iframe id="frm" src="page.aspx?p1=1">

Or code behind:

Iframe.Attributes["src"] = "page.aspx?p1=" + HttpUtility.UrlEncode(p1);

You can check this link:

http://www.codeproject.com/KB/aspnet/IFrameParams.aspx

Hope this can help you.

[RESOLVED] Show the data in label control

I have a store procedure. I show the result in the grid view, I would like to know how I can show each fields in the label so I can place them anywhere that I like in the page.

This is my code:

 

using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
        {

            SqlCommand cmd = new SqlCommand("w_create_order", connection);
            cmd.CommandType = CommandType.StoredProcedure;


            //input parameters  
            cmd.Parameters.AddWithValue("@in_order_class", "WEB");
            cmd.Parameters.AddWithValue("@in_owner_code", "OP");
            cmd.Parameters.AddWithValue("@in_sales_campaign_code", "DEF");
            cmd.Parameters.AddWithValue("@in_cus_key", null);
            cmd.Parameters.AddWithValue("@in_lab_key", null);
            cmd.Parameters.AddWithValue("@in_invoice_number", null);
            connection.Open();

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            SqlDataReader rdr = null;
            rdr = cmd.ExecuteReader();

            GridView1.DataSource = rdr;
            GridView1.DataBind();
            connection.Close();

 

nikoo56

would like to know how I can show each fields in the label so I can place them anywhere that I like in the page.
 

Like this..

while (rdr.Read())
    {
        Label1.Text = rdr["YourColumnName"].ToString();

    }

You are using datareader and its simple to get data from data reader .. use the datareader read method to read data from

data reader ... or if you want to get data from the gridview row so

You have to use Gridview RowDatabound event to get data from gridview.. like

e.row.dataitem


Thanks Hope this will help and one thing more your question is not clear .