Click here to Skip to main content
15,903,831 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here is mine code:
C#
SqlConnection conn = new SqlConnection("Data Source=TWS\\SQLEXPRESS; Database=db_umesh; Integrated Security=True;");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fillgv();
        }
    }
    private void fillgv()
    {
        string qry = "select * from tbl_course";
        SqlCommand cmd = new SqlCommand(qry,conn);
        try
        {
            cmd.Connection.Open();
            gv.DataSource = cmd.ExecuteReader();
            gv.DataBind();
        }
        catch (Exception ex)
        {
            ltrl_msg.Text = ex.ToString();
        }
        finally
        {
            conn.Close();
        }
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.DataItem. ==ListItemType.Item)
        {
        }
        //if (e.Row.RowType.ToString() == ListItemType.Item.ToString() || e.Row.RowType.ToString() == ListItemType.AlternatingItem.ToString())
        //{
        //    //((HtmlInputHidden)e.Row.FindControl("hid")).Value = DataBinder.Eval(e.Row.RowType, "Course_id").ToString();
        //    ((Literal)e.Row.FindControl("ltrl")).Text = DataBinder.Eval(e.Row.RowType, "Course_name").ToString();
        //}
        
       
    }
}

gridviewex.aspx
XML
<div>
        <asp:GridView runat="server" ID="gv" AutoGenerateColumns="false" PageSize="5"
            GridLines="None" Width="80%"  align="center" onrowdatabound="gv_RowDataBound" >
                <HeaderStyle BackColor="#84A8C9" />
                <AlternatingRowStyle BackColor="#F4FAFF" />
                <RowStyle BackColor="#DBECFB" />
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <font color="#F4FAFF"><b>Action</b></font>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="chkid" Width="16" />
                            <asp:Button ID="Button1" runat="server" Text="Edit" CommandName="edit" />
                            <asp:Button ID="Button2" runat="server" Text="del" CommandName="del" />
                            <input id="hid" runat="server" type="hidden" />
                        </ItemTemplate>
                        <ItemStyle Height="12%" Width="13%" />
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <font color="#F4FAFF"><b>Name</b></font>
                        </HeaderTemplate>
                        <ItemTemplate>
                             <font color="#034f94">&nbsp;&nbsp;
                                 <%--<asp:Label ID="lblName" runat="server" Text='<%#Eval("Course_name") %>' />--%>
                                 <asp:Literal ID="ltrl" runat="server"></asp:Literal>
                             </font>
                        </ItemTemplate>
                        <ItemStyle Height="12%" HorizontalAlign="Left" Width="28%" />
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <font color="#F4FAFF"><b>Duration</b></font>
                        </HeaderTemplate>
                        <ItemTemplate>
                             <font color="#034f94">&nbsp;&nbsp;
                                 <asp:Literal ID="lt_fees" runat="server" ></asp:Literal>
                             </font>
                        </ItemTemplate>
                        <ItemStyle Height="12%" HorizontalAlign="Left" Width="28%" />
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    </div>
    <asp:Literal runat="server" ID="ltrl_msg"></asp:Literal>


i have problem how to bind this its given error
please help me.
thanks
Posted
Updated 3-Mar-11 20:32pm
v2
Comments
m@dhu 4-Mar-11 2:33am    
What error did you get.
UD(IA) 4-Mar-11 3:54am    
thanks for reply there is no problem but not value shows in grid view.
ok
if values shows then it would like to update and delete value from the button in front of that data.
OriginalGriff 4-Mar-11 2:44am    
You need to edit your question and tell us what error you are getting: otherwise we are working in the dark...
UD(IA) 4-Mar-11 3:53am    
thnaks for reply
my problem is that i would like to create a grid view and its having one check box and one edit button and another is for delete when i click on edit button one panel will be displayed with all selected rows values and user can change in these values and when he/she will click on save than in grid view its reflect change.
thanks again
R. Giskard Reventlov 4-Mar-11 3:42am    
Cross post: you asked this again (and have now been answered). If the other is incorrect delete both questions and start again.

1 solution

Prospective answer[^] given in other post.
 
Share this answer
 
Comments
UD(IA) 4-Mar-11 3:56am    
is there no need to use alternate text type properties like we earlier use with datagrid.
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900