https://drive.google.com/file/d/0B0UtWe2VURW1MmQ4c2JBTUFmMWs/edit?usp=sharing
i have a simple page which contains a gridview , in it is more linkbutton , on selecting link button i will values of gridview record in text boxes.
i will llike to view gridview data in textboxes when i click a template field
here is the code
<div id="body">
<div id="header"></div>
<div id="main">
<div id="content-1">
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2"
HeaderStyle-ForeColor="White" Width="240px"
runat="SERVER" AutoGenerateColumns="False"
OnSelectedIndexChanged = "OnSelectedIndexChanged" GridLines="None"
CellPadding="4" EnableModelValidation="True" ForeColor="#333333">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="CA_REF_NO" HeaderText="CA_REF_NO" ItemStyle-Width="150"
Visible="false" ControlStyle-BorderStyle="None" >
<ControlStyle BorderStyle="None"></ControlStyle>
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="CA_TITLE" HeaderText="Title" ItemStyle-Width="150"
Visible="false" >
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<%-- <a href="#<%#Eval("CA_TITLE")%>" id="a2"><%#Eval("CA_TITLE")%></a>--%>
<asp:Label ID="lblCA_TITLE" Text='<%# Eval("CA_TITLE") %>' runat="SERVER" />
<asp:LinkButton Text="More" ID="lnkSelect" runat="SERVER" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CA_ANNOUNCE_DESC" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCA_ANNOUNCE_DESC" Text='<%# Eval("CA_ANNOUNCE_DESC") %>' runat="SERVER" Visible="false"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CA_ANNOUNCE_DESC_A" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCA_ANNOUNCE_DESC_A" Text='<%# Eval("CA_ANNOUNCE_DESC_A") %>' runat="SERVER" Visible="false"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CA_CRE_BY" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCA_CRE_BY" Text='<%# Eval("CA_CRE_BY") %>' runat="SERVER" Visible="false"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CA_CRE_DATE" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCA_CRE_DATE" Text='<%# Eval("CA_CRE_DATE") %>' runat="SERVER" Visible="false"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True"></HeaderStyle>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView></div>
<div id="content-2">
<div id="content-2-1"><asp:Label ID="lblTitle" runat="server" Text="Title"></asp:Label>
<asp:TextBox ID="txtTitle" runat="server" Width="300px"></asp:TextBox>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
<div id="content-2-2">
<asp:TextBox ID="txt_CA_ANNOUNCE_DESC_A" runat="server" TextMode="MultiLine"
Width="660px" Height="290px" Font-Bold="False" Font-Size="Large"></asp:TextBox>
</div>
<br />
<div id="content-2-3">
<asp:TextBox ID="txt_CA_ANNOUNCE_DESC" runat="server" TextMode="MultiLine"
Width="660px" Height="290px" Font-Size="Medium"></asp:TextBox>
</div>
<br />
<div id="content-2-4">
<asp:Label ID="lblCA_CRE_BY" runat="server" Text="Post By"></asp:Label>
<asp:TextBox ID="txt_cre_by" runat="server" Width="250px"></asp:TextBox>
<asp:Label ID="lblCA_CRE_DATE" runat="server" Text="Date Posted"></asp:Label>
<asp:TextBox ID="txt_cre_date" runat="server"></asp:TextBox> </div>
</div></div>
<div id="footer"></div>
</div>
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["CA_REF_NO"] != null)
{
get_ca_ref_no();
}
BindRepeaterData();
}
protected void BindRepeaterData()
{
OracleConnection con = new OracleConnection(strConnString);
try
{
con.Open();
OracleCommand cmd = new OracleCommand("SELECT * FROM COMP_ANNOUNCE order by nvl(CA_EXPIRY_DATE,sysdate) DESC", con);
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
lblMessage.Text = "No Data !";
}
}
catch (ThreadAbortException)
{
//
}
catch (Exception ex)
{
// lblMessage.Text = ex.Message;
Session["ErrorMessage"] = ex.Message;
Response.Redirect("ErrorMsg.aspx");
}
finally
{
if (con != null)
{
con.Close();
}
}
}
protected void get_ca_ref_no()
{
// CODE TO GET DATA OF QUERY STRING.
OracleConnection con = new OracleConnection(strConnString);
try
{
con.Open();
OracleCommand cmd = new OracleCommand("SELECT * FROM COMP_ANNOUNCE where CA_REF_NO=" + "'" + Request.QueryString["CA_REF_NO"].ToString() + "'", con);
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
txtTitle.Text = ds.Tables[0].Rows[0]["CA_TITLE"].ToString();
txt_CA_ANNOUNCE_DESC.Text = ds.Tables[0].Rows[0]["CA_ANNOUNCE_DESC"].ToString();
txt_CA_ANNOUNCE_DESC_A.Text = ds.Tables[0].Rows[0]["CA_ANNOUNCE_DESC_A"].ToString();
txt_cre_by.Text = ds.Tables[0].Rows[0]["CA_CRE_BY"].ToString();
txt_cre_date.Text = ds.Tables[0].Rows[0]["CA_CRE_DATE"].ToString();
}
else
{
lblMessage.Text = "No Data !";
}
}
catch (ThreadAbortException)
{
//
}
catch (Exception ex)
{
// lblMessage.Text = ex.Message;
Session["ErrorMessage"] = ex.Message;
Response.Redirect("ErrorMsg.aspx");
}
finally
{
if (con != null)
{
con.Close();
}
}
}
//protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
//{
// int index = GridView1.SelectedIndex;
// lblMessage.Text = "The primary key value of the selected row is" + GridView1.DataKeys[index].Value.ToString() + ".";
//}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
int selectedRowIndex;
selectedRowIndex = GridView1.SelectedIndex + 1;
GridViewRow row = GridView1.SelectedRow;
//int index = selectedRowIndex.ToString();
//lblMessage.Text = "The primary key value of the selected row is" + GridView1.DataKeys[selectedRowIndex].Value.ToString() + ".";
txtTitle.Text = (row.FindControl("lblCA_TITLE") as Label).Text;
txt_CA_ANNOUNCE_DESC.Text = (row.FindControl("lblCA_ANNOUNCE_DESC") as Label).Text;//row.Cells[2].Text;
txt_CA_ANNOUNCE_DESC_A.Text = (row.FindControl("lblCA_ANNOUNCE_DESC_A") as Label).Text;
txt_cre_by.Text = (row.FindControl("lblCA_CRE_BY") as Label).Text;
txt_cre_date.Text = (row.FindControl("lblCA_CRE_DATE") as Label).Text;
}